{"_id":"vectorclock","_rev":"5-b0f53fa7312f379a4db0dfd8bf11aac4","name":"vectorclock","description":"A simple implementation of vector clocks in Javascript.","dist-tags":{"latest":"0.0.0"},"versions":{"0.0.0":{"name":"vectorclock","version":"0.0.0","description":"A simple implementation of vector clocks in Javascript.","main":"index.js","directories":{"test":"test"},"scripts":{"test":"./node_modules/.bin/mocha --ui exports --reporter spec --slow 2000ms --bail test/test.js"},"repository":{"type":"git","url":"https://github.com/mixu/vectorclock.git"},"keywords":["vector","clock","vector","logical","clock","time","version","versioning","conflict","compare","distributed"],"author":{"name":"Mikito Takada","email":"mikito.takada@gmail.com"},"license":"BSD","devDependencies":{"mocha":"~1.7.0"},"readme":"# vectorclock\n\nA simple implementation of vector clocks in Javascript.\n\n## API\n\n[Vector clocks](http://en.wikipedia.org/wiki/Vector_clock) are represented as plain old objects with a \"clock\" key (which is a hash). For example: `{ clock: { a: 1, b: 2 } }`.\n\nRecommended reading:\n\n- Leslie Lamport (1978). \"[Time, clocks, and the ordering of events in a distributed system](https://www.google.com/search?q=Time%2C+clocks%2C+and+the+ordering+of+events+in+a+distributed+system)\". Communications of the ACM 21 (7): 558-565.\n- Friedemann Mattern (1988). \"[Virtual Time and Global States of Distributed Systems](https://www.google.com/search?q=Virtual%20Time%20and%20Global%20States%20of%20Distributed%20Systems)\". Workshop on Parallel and Distributed Algorithms: pp. 215-226\n- Colin Fidge (1988), \"[Timestamps in Message-Passing Systems That Preserve the Partial Ordering](https://www.google.com/search?q=Timestamps+in+Message-Passing+Systems+That+Preserve+the+Partial+Ordering)\".\n\n## API\n\n- `increment(clock, nodeId)`: increment a vector clock at \"nodeId\"\n- `merge(a, b)`: given two vector clocks, returns a new vector clock with all values greater than those of the merged clocks\n- `compare(a, b)` / `ascSort(a, b)`: compare two vector clocks, returns -1 for a < b and 1 for a > b; 0 for concurrent and identical values. Can be used to sort an array of objects by their \"clock\" key via [].sort(VClock.ascSort)\n- `descSort(a, b)`: sorts in descending order (N, ... 3, 2, 1)\n- `isConcurrent(a, b)`: if A and B are equal, or if they occurred concurrently.\n- `isIdentical(a, b)`: if every value in both vector clocks is equal.\n\n## Implementing read repair using vector clocks\n\nHere is one way to implement read repair by detecting which clocks are concurrent, and if necessary, returning multiple values:\n\n    var responses = [ { clock: ... }, { clock: ... }];\n    // sort the responses by the vector clocks\n    responses.sort(VClock.descSort);\n    // then compare them to the topmost\n    // (in sequential order, the greatest) item\n    var repaired = [ responses.shift() ];\n    responses.forEach(function(item, index) {\n      // if they are concurrent with that item, then there is a conflict\n      // that we cannot resolve, so we need to return the item.\n      if(VClock.isConcurrent(item, repaired[0]) &&\n        !VClock.isIdentical(item, repaired[0])) {\n        repaired.push(item);\n      }\n    });\n","_id":"vectorclock@0.0.0","dist":{"shasum":"8166ab0fca7e898285e5cb0feb410b90fe941e6b","tarball":"https://registry.npmjs.org/vectorclock/-/vectorclock-0.0.0.tgz","integrity":"sha512-i+u7iaoSOnah4G+eCzrazS9AA0ZGOs74Lh2wqrrj9+DeFfYgBS/D4KIdkjN855DBsIq9l4i6yl5azOLvEtrYSA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAFqPGb0qFhGQ2u1bLcUFpCmOH/mP4sgHFFM2Ql8PTYkAiBolG8rjKxQZvRsS5phtsJ3LlNOh1ciuLFT9D4kisRkfw=="}]},"_npmVersion":"1.1.59","_npmUser":{"name":"mixu","email":"mixu@mixu.net"},"maintainers":[{"name":"mixu","email":"mixu@mixu.net"}]}},"readme":"# vectorclock\n\nA simple implementation of vector clocks in Javascript.\n\n## API\n\n[Vector clocks](http://en.wikipedia.org/wiki/Vector_clock) are represented as plain old objects with a \"clock\" key (which is a hash). For example: `{ clock: { a: 1, b: 2 } }`.\n\nRecommended reading:\n\n- Leslie Lamport (1978). \"[Time, clocks, and the ordering of events in a distributed system](https://www.google.com/search?q=Time%2C+clocks%2C+and+the+ordering+of+events+in+a+distributed+system)\". Communications of the ACM 21 (7): 558-565.\n- Friedemann Mattern (1988). \"[Virtual Time and Global States of Distributed Systems](https://www.google.com/search?q=Virtual%20Time%20and%20Global%20States%20of%20Distributed%20Systems)\". Workshop on Parallel and Distributed Algorithms: pp. 215-226\n- Colin Fidge (1988), \"[Timestamps in Message-Passing Systems That Preserve the Partial Ordering](https://www.google.com/search?q=Timestamps+in+Message-Passing+Systems+That+Preserve+the+Partial+Ordering)\".\n\n## API\n\n- `increment(clock, nodeId)`: increment a vector clock at \"nodeId\"\n- `merge(a, b)`: given two vector clocks, returns a new vector clock with all values greater than those of the merged clocks\n- `compare(a, b)` / `ascSort(a, b)`: compare two vector clocks, returns -1 for a < b and 1 for a > b; 0 for concurrent and identical values. Can be used to sort an array of objects by their \"clock\" key via [].sort(VClock.ascSort)\n- `descSort(a, b)`: sorts in descending order (N, ... 3, 2, 1)\n- `isConcurrent(a, b)`: if A and B are equal, or if they occurred concurrently.\n- `isIdentical(a, b)`: if every value in both vector clocks is equal.\n\n## Implementing read repair using vector clocks\n\nHere is one way to implement read repair by detecting which clocks are concurrent, and if necessary, returning multiple values:\n\n    var responses = [ { clock: ... }, { clock: ... }];\n    // sort the responses by the vector clocks\n    responses.sort(VClock.descSort);\n    // then compare them to the topmost\n    // (in sequential order, the greatest) item\n    var repaired = [ responses.shift() ];\n    responses.forEach(function(item, index) {\n      // if they are concurrent with that item, then there is a conflict\n      // that we cannot resolve, so we need to return the item.\n      if(VClock.isConcurrent(item, repaired[0]) &&\n        !VClock.isIdentical(item, repaired[0])) {\n        repaired.push(item);\n      }\n    });\n","maintainers":[{"name":"mixu","email":"mixu@mixu.net"}],"time":{"modified":"2022-06-28T09:47:17.175Z","created":"2012-11-16T19:44:02.617Z","0.0.0":"2012-11-16T19:44:03.731Z"},"author":{"name":"Mikito Takada","email":"mikito.takada@gmail.com"},"repository":{"type":"git","url":"https://github.com/mixu/vectorclock.git"}}