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

Method Add

factstore/factstore.go:436–463  ·  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

434
435// Add implements the FactStore interface by adding the fact to the backing map.
436func (s IndexedInMemoryStore) Add(a ast.Atom) bool {
437 if a.Predicate.Arity == 0 {
438 _, ok := s.constants[a.Predicate]
439 if !ok {
440 s.constants[a.Predicate] = a
441 return true
442 }
443 return false
444 }
445 h := a.Args[0].Hash()
446 shard, ok := s.shardsByPredicate[a.Predicate]
447 if !ok {
448 shard = map[uint64]map[uint64]ast.Atom{h: {a.Hash(): a}}
449 s.shardsByPredicate[a.Predicate] = shard
450 return true
451 }
452 key := a.Hash()
453 atoms, ok := shard[h]
454 if !ok {
455 shard[h] = map[uint64]ast.Atom{a.Hash(): a}
456 return true
457 }
458 if _, ok := atoms[key]; !ok {
459 atoms[key] = a
460 return true
461 }
462 return false
463}
464
465// Remove removes the fact to the backing map.
466func (s IndexedInMemoryStore) Remove(a ast.Atom) bool {

Callers 2

MergeMethod · 0.95
BenchmarkJoinFunction · 0.95

Calls 1

HashMethod · 0.65

Tested by 1

BenchmarkJoinFunction · 0.76