Currently the graph has unlabelled edges. The task is to add support for labelled edges.
The way the edges are currently stored as KV pairs in badger are as follows:
The src node is the key and the value is a list of destination nodes which are stored as map[string]bool in the codebase where the string is the dest node and the bool does not really mean anything. This map[string]bool is serialized to []byte using gob and is Set as the Value in badger. Please refer to the Internals section of the CONTRIBUTING.md for more details on how the internal storage representation works
Modify this to use map[string]map[string]bool where the first string is the label and the map[string]bool succeeding it is the same as before.
The following functions will also need to be modified to account for labels: AddEdge, RemoveEdge, GetEdges, OutEdges, IterAllEdges and basically any other function that got added in the course of hacknight itself except maybe for PickRandomVertex
Have GetEdges, OutEdges and IterAllEdges take in a label and allow support for passing in "" as the wildcard operator to operate on all edges. Consequently you will have to modify AddEdge and RemoveEdge to disallow "" being passed as a label.
Please update the function calls lib_test.go file since you are making breaking changes to the API and write unit tests for testing Labelled Edges
psst, remember to update the usage guide in the README too 👀
Currently the graph has unlabelled edges. The task is to add support for labelled edges.
The way the edges are currently stored as KV pairs in badger are as follows:
The src node is the key and the value is a list of destination nodes which are stored as
map[string]boolin the codebase where thestringis the dest node and the bool does not really mean anything. Thismap[string]boolis serialized to[]byteusinggoband isSetas the Value in badger. Please refer to the Internals section of the CONTRIBUTING.md for more details on how the internal storage representation worksModify this to use
map[string]map[string]boolwhere the firststringis the label and themap[string]boolsucceeding it is the same as before.The following functions will also need to be modified to account for labels:
AddEdge,RemoveEdge,GetEdges,OutEdges,IterAllEdgesand basically any other function that got added in the course of hacknight itself except maybe forPickRandomVertexHave
GetEdges,OutEdgesandIterAllEdgestake in a label and allow support for passing in "" as the wildcard operator to operate on all edges. Consequently you will have to modifyAddEdgeandRemoveEdgeto disallow "" being passed as a label.Please update the function calls
lib_test.gofile since you are making breaking changes to the API and write unit tests for testing Labelled Edgespsst, remember to update the usage guide in the README too 👀