mirror of
https://source.quilibrium.com/quilibrium/ceremonyclient.git
synced 2024-11-14 04:05:17 +00:00
6c567a04c1
* v1.4.20 base * add inmemory dev mock for hypergraph * add simple rdf + tr * Update config.go (#234) 2 of bootstrap nodes are going to be closed due to low performances. Will consider to replace with better specs. * go mod tidy * go mod tidy * bump name in readme --------- Co-authored-by: 0xOzgur <29779769+0xOzgur@users.noreply.github.com>
90 lines
2.1 KiB
Go
90 lines
2.1 KiB
Go
package inmem
|
|
|
|
func InShard(a Atom, l Location) bool {
|
|
return a.GetLocation() == l
|
|
}
|
|
|
|
type ShardSet struct {
|
|
VertexSet *IdSet
|
|
HyperedgeSet *IdSet
|
|
}
|
|
|
|
func ShardAtom(a Atom) map[Location]*ShardSet {
|
|
switch atom := a.(type) {
|
|
case *Vertex:
|
|
return ShardVertex(atom)
|
|
case *Hyperedge:
|
|
return ShardHyperedge(atom)
|
|
default:
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func ShardAtomSet(atomSet map[string]Atom) map[Location]*ShardSet {
|
|
result := make(map[Location]*ShardSet)
|
|
for _, a := range atomSet {
|
|
result[a.GetLocation()] = &ShardSet{
|
|
VertexSet: NewIdSet("vertex"),
|
|
HyperedgeSet: NewIdSet("hyperedge"),
|
|
}
|
|
}
|
|
|
|
for _, atom := range atomSet {
|
|
shard := ShardAtom(atom)
|
|
for location, locationShard := range shard {
|
|
for _, locationAtom := range locationShard.VertexSet.atoms {
|
|
if _, ok := result[location]; !ok {
|
|
result[location] = &ShardSet{
|
|
VertexSet: NewIdSet("vertex"),
|
|
HyperedgeSet: NewIdSet("hyperedge"),
|
|
}
|
|
}
|
|
result[location].VertexSet.Add(locationAtom)
|
|
}
|
|
for _, locationAtom := range locationShard.HyperedgeSet.atoms {
|
|
if _, ok := result[location]; !ok {
|
|
result[location] = &ShardSet{
|
|
VertexSet: NewIdSet("vertex"),
|
|
HyperedgeSet: NewIdSet("hyperedge"),
|
|
}
|
|
}
|
|
result[location].HyperedgeSet.Add(locationAtom)
|
|
}
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
|
|
func ShardVertex(v *Vertex) map[Location]*ShardSet {
|
|
result := make(map[Location]*ShardSet)
|
|
if _, ok := result[v.location]; !ok {
|
|
result[v.location] = &ShardSet{
|
|
VertexSet: NewIdSet("vertex"),
|
|
HyperedgeSet: NewIdSet("hyperedge"),
|
|
}
|
|
}
|
|
result[v.location].VertexSet.Add(v)
|
|
return result
|
|
}
|
|
|
|
// ShardHyperedge shards a hyperedge and its extrinsics across locations.
|
|
func ShardHyperedge(h *Hyperedge) map[Location]*ShardSet {
|
|
extrinsicShardSet := ShardAtomSet(h.extrinsics)
|
|
result := make(map[Location]*ShardSet)
|
|
|
|
for l, s := range extrinsicShardSet {
|
|
result[l] = s
|
|
}
|
|
|
|
if _, ok := result[h.location]; !ok {
|
|
result[h.location] = &ShardSet{
|
|
VertexSet: NewIdSet("vertex"),
|
|
HyperedgeSet: NewIdSet("hyperedge"),
|
|
}
|
|
}
|
|
|
|
result[h.location].HyperedgeSet.Add(h)
|
|
|
|
return result
|
|
}
|