package mdb import ( "fmt" "reflect" ) func (m *itemMap[T]) Equals(rhs *itemMap[T]) error { return m.EqualsMap(rhs.m) } func (m *itemMap[T]) EqualsMap(data map[uint64]*T) error { if len(data) != len(m.m) { return fmt.Errorf("Expected %d items, but found %d.", len(data), len(m.m)) } for key, exp := range data { val, ok := m.m[key] if !ok { return fmt.Errorf("No value for %d. Expected: %v", key, *exp) } if !reflect.DeepEqual(*val, *exp) { return fmt.Errorf("Value mismatch %d: %v != %v", key, *val, *exp) } } return nil } func (m *itemMap[T]) EqualsKV() (err error) { count := 0 m.kv.Iterate(m.collection, func(id uint64, data []byte) { count++ if err != nil { return } item := decode[T](data) val, ok := m.m[id] if !ok { err = fmt.Errorf("Item %d not found in memory: %v", id, *item) return } if !reflect.DeepEqual(*item, *val) { err = fmt.Errorf("Items not equal %d: %v != %v", id, *item, *val) return } }) if err == nil && count != len(m.m) { err = fmt.Errorf("%d items on disk, but %d in memory", count, len(m.m)) } return err }