Add implements the FactStore interface by adding the fact to the backing map.
(a ast.Atom)
| 434 | |
| 435 | // Add implements the FactStore interface by adding the fact to the backing map. |
| 436 | func (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. |
| 466 | func (s IndexedInMemoryStore) Remove(a ast.Atom) bool { |