Added count functionality

master v0.5.0
jdl 2023-11-21 18:35:37 +01:00
parent 9078335d70
commit 5528c264d3
2 changed files with 9 additions and 0 deletions

View File

@ -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)

View File

@ -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 {