0.3.69 • Published 2 days ago

@thi.ng/vclock v0.3.69

Weekly downloads
4
License
Apache-2.0
Repository
github
Last release
2 days ago

vclock

npm version npm downloads Twitter Follow

This project is part of the @thi.ng/umbrella monorepo.

About

Vector clock functions for synchronizing distributed states & processes.

Vector clock algorithm:

  • Initially all clocks are zero.
  • Each time a process experiences an internal event, it increments its own logical clock in the vector by one (inc()).
  • Each time a process sends a message, it increments its own logical clock in the vector by one and then sends a copy of its own vector.
  • Each time a process receives a message, it increments its own logical clock in the vector by one and updates each element in its vector by taking the maximum of the value in its own vector clock and the value in the vector in the received message (merge()).

The package provides the following immutable vector clock operations, where vector clocks are plain JS objects:

  • inc(clock, id) - increment (or create) clock component
  • remove(clock, id) - remove clock component
  • merge(a, b) - merge two vector clocks
  • signedSkew(a, b) - max signed difference between vector clocks
  • absSkew(a, b) - max unsigned difference between vector clocks
  • compare(a, b) - comparator for logically ordering vector clocks
  • isBefore(a, b) - true if a < b
  • isAfter(a, b) - true if a > b
  • isConcurrent(a, b) - if both clocks represent concurrent updates
  • equiv(a, b) - equality predicate
  • orderAsc(a, b) - alias for compare()
  • orderDesc(a, b) - reverse order to orderAsc()

References:

Status

BETA - possibly breaking changes forthcoming

Search or submit any issues for this package

Installation

yarn add @thi.ng/vclock

ES module import:

<script type="module" src="https://cdn.skypack.dev/@thi.ng/vclock"></script>

Skypack documentation

For Node.js REPL:

# with flag only for < v16
node --experimental-repl-await

> const vclock = await import("@thi.ng/vclock");

Package sizes (gzipped, pre-treeshake): ESM: 470 bytes

Dependencies

API

Generated API docs

TODO

Authors

Karsten Schmidt

If this project contributes to an academic publication, please cite it as:

@misc{thing-vclock,
  title = "@thi.ng/vclock",
  author = "Karsten Schmidt",
  note = "https://thi.ng/vclock",
  year = 2018
}

License

© 2018 - 2021 Karsten Schmidt // Apache Software License 2.0

0.3.69

2 days ago

0.3.68

17 days ago

0.3.67

20 days ago

0.3.66

29 days ago

0.3.65

1 month ago

0.3.64

1 month ago

0.3.63

2 months ago

0.3.62

2 months ago

0.3.61

2 months ago

0.3.60

2 months ago

0.3.59

2 months ago

0.3.58

3 months ago

0.3.57

3 months ago

0.3.56

3 months ago

0.3.53

3 months ago

0.3.52

3 months ago

0.3.55

3 months ago

0.3.54

3 months ago

0.3.51

3 months ago

0.3.50

4 months ago

0.3.49

4 months ago

0.3.48

4 months ago

0.3.47

5 months ago

0.3.46

5 months ago

0.3.45

5 months ago

0.3.44

5 months ago

0.3.39

7 months ago

0.3.38

9 months ago

0.3.37

9 months ago

0.3.36

9 months ago

0.3.35

9 months ago

0.3.33

9 months ago

0.3.42

6 months ago

0.3.41

6 months ago

0.3.43

5 months ago

0.3.32

11 months ago

0.3.31

12 months ago

0.3.30

1 year ago

0.3.29

1 year ago

0.3.28

1 year ago

0.3.27

1 year ago

0.3.26

1 year ago

0.3.25

1 year ago

0.3.23

1 year ago

0.3.20

1 year ago

0.3.22

1 year ago

0.3.21

1 year ago

0.3.19

1 year ago

0.3.17

1 year ago

0.3.16

1 year ago

0.3.15

2 years ago

0.3.14

2 years ago

0.3.13

2 years ago

0.3.18

1 year ago

0.3.12

2 years ago

0.3.11

2 years ago

0.3.9

2 years ago

0.3.10

2 years ago

0.3.8

2 years ago

0.3.6

2 years ago

0.3.7

2 years ago

0.3.5

2 years ago

0.3.4

2 years ago

0.3.0

2 years ago

0.2.8

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.3

2 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.4

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.1.16

3 years ago

0.1.15

3 years ago

0.1.13

3 years ago

0.1.14

3 years ago

0.1.12

3 years ago

0.1.11

3 years ago

0.1.10

3 years ago

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago