Module for a lightweight LWWElementGraph, which uses LWWElementSet. Handles merges in a Last Write Wins Manner.
Module for a lightweight LWWElementSet in Python. Handles merges in a Last Write Wins Manner.
To install packages, perform:
pip install LWWElementGraph
- /tests/testLWWElementSet.py
- /tests/testLWWElementGraph.py
- /tests/testIntegration.py
Bases: object
Initializing Vertices and Edges as LWWElementSet. Maintaining live updating graphState to optimize reads (getNeighborsOf, findPath)
If vertex1, vertex2 present, add edge to edges.addSet. Maintain graphState Runs in O(1)
Adds the Vertex to vertices LWWSet. Also maintains graphState for read optimization Runs in O(1)
Perform BFS for shortest path. Uses graphState which was optimized for read to get all the neighbours of a vertex in O(1). Runs in O(V + E)
O(1) query for all the vertices connected to the query vertex. Uses graphState which was optimized for read
Check if vertex is valid, runs in O(1)
Merging Graphs by merging their Vertice and Edge LLWSet. Remove Edge if Vertex not present anymore after merge. Recompute the internal graphState as well. Runs in O(V + E)
If edge present, add it to edges.removeSet. Maintain graphState. Runs in O(E) because of _removeEdge
If vertex is present, then add it to vertices.removeSet. Add each of its edge to edges.removeSet. Also maintains graphState for read optimization. Runs in O(E) because of _removeVertex
Bases: object
Initialize addSet and removeSet to empty dictionary. iData and iTimestamp are the index of the data and timestamp respectively
Adds in the addSet. If element already in addSet, replace timestamp with now()
Returns all the valid members. Go through addSet, check if it is a member
Element is a member if it is in addSet, and either not removeSet, or in removeSet but with an earlier timestamp than it’s timestamp in addSet
Prioritize Last Write. Since elements are in the form (data, datetime), reverse them to compare by datetime and take max. Then, reverse back the max and store in merged
Merge self with otherLWWElementSet in LWW manner
Adds in the removeSet. Cannot remove if not already in addSet