func()

in frequencies/items_sketch.go [322:351]


func (i *ItemsSketch[C]) UpdateMany(item C, count int64) error {
	if internal.IsNil(item) || count == 0 {
		return nil
	}
	if count < 0 {
		return fmt.Errorf("count may not be negative")
	}

	i.streamWeight += count
	err := i.hashMap.adjustOrPutValue(item, count)
	if err != nil {
		return err
	}

	if i.GetNumActiveItems() > i.curMapCap { //over the threshold, we need to do something
		if i.hashMap.lgLength < i.lgMaxMapSize { //below tgt size, we can grow
			err := i.hashMap.resize(2 * len(i.hashMap.keys))
			if err != nil {
				return err
			}
			i.curMapCap = i.hashMap.getCapacity()
		} else {
			i.offset += i.hashMap.purge(i.sampleSize)
			if i.GetNumActiveItems() > i.GetMaximumMapCapacity() {
				return fmt.Errorf("purge did not reduce active items")
			}
		}
	}
	return nil
}