MCPcopy
hub / github.com/google/mangle / Add

Method Add

factstore/factstore.go:596–635  ·  view source on GitHub ↗

Add implements the FactStore interface by adding the fact to the backing map.

(a ast.Atom)

Source from the content-addressed store, hash-verified

594
595// Add implements the FactStore interface by adding the fact to the backing map.
596func (s MultiIndexedInMemoryStore) Add(a ast.Atom) bool {
597 if a.Predicate.Arity == 0 {
598 _, ok := s.constants[a.Predicate]
599 if !ok {
600 s.constants[a.Predicate] = a
601 return true
602 }
603 return false
604 }
605 aHash := a.Hash()
606 shard, ok := s.shardsByPredicate[a.Predicate]
607 if !ok {
608 shard = make(map[uint16]map[uint64]map[uint64]*ast.Atom)
609 s.shardsByPredicate[a.Predicate] = shard
610 for i := 0; i < a.Predicate.Arity; i++ {
611 iHash := a.Args[i].Hash()
612 shard[uint16(i)] = map[uint64]map[uint64]*ast.Atom{iHash: {aHash: &a}}
613 }
614 return true
615 }
616 added := false
617 for i := 0; i < a.Predicate.Arity; i++ {
618 iHash := a.Args[i].Hash()
619 params, ok := shard[uint16(i)]
620 if !ok {
621 shard[uint16(i)] = map[uint64]map[uint64]*ast.Atom{iHash: {aHash: &a}}
622 added = true
623 continue
624 }
625 atoms, ok := params[iHash]
626 if !ok {
627 params[iHash] = map[uint64]*ast.Atom{aHash: &a}
628 added = true
629 } else if _, ok := atoms[aHash]; !ok {
630 atoms[aHash] = &a
631 added = true
632 }
633 }
634 return added
635}
636
637// Remove implementation for FactStoreWithRemove.
638func (s MultiIndexedInMemoryStore) Remove(a ast.Atom) bool {

Callers 1

MergeMethod · 0.95

Calls 1

HashMethod · 0.65

Tested by

no test coverage detected