diff --git a/mdb/collection.go b/mdb/collection.go index 2571ccf..d044286 100644 --- a/mdb/collection.go +++ b/mdb/collection.go @@ -274,6 +274,10 @@ func (c *Collection[T]) delete(tx *Snapshot, itemID uint64) error { return c.deleteItem(tx, itemID) } +func (c *Collection[T]) Count(tx *Snapshot) int { + return c.ByID.Count(tx) +} + func (c *Collection[T]) getByID(tx *Snapshot, itemID uint64) (*T, bool) { x := new(T) c.setID(x, itemID) diff --git a/mdb/index.go b/mdb/index.go index a370fa2..f28ac7a 100644 --- a/mdb/index.go +++ b/mdb/index.go @@ -192,6 +192,11 @@ func (i *Index[T]) List(tx *Snapshot, args *ListArgs[T], out []*T) []*T { return items } +func (i *Index[T]) Count(tx *Snapshot) int { + tx = i.ensureSnapshot(tx) + return i.btree(tx).Len() +} + // ---------------------------------------------------------------------------- func (i *Index[T]) insertConflict(tx *Snapshot, item *T) bool {