This is a simple LWW Element Set implementation in javascript.
To initialize everything, ensure you have node.js installed. cd into the project folder and run:
npm install
To test the library, run this command:
node lww-tests.js
To run the library, just import it into your javascript project
The main LWW functions are in main.js.
In this implementation, added elements are stored in the _addSet
. Removed elements are stored in the _removeSet
.
Elements contain: an elem
(element, or data) and time
(Can be an integer, or when not provided, the current timestamp).
Here is a brief description of every function:
This is the entrypoint to the module. It takes in 3 parameters:
addBias
,addSet
andremoveSet
.
This function adds a new element to the
_addSet
set.
This function adds a new element to the
_removeSet
Compares
T
with the current set (this
). If they are identical, returnstrue
, otherwise returnsfalse
.
Merges
T
inttothis
, and returnsthis
set.
Searches for
data
in the current set. If found, returnstrue
, otherwisefalse
.