mirror of
https://github.com/bloeys/nset.git
synced 2025-12-29 06:28:19 +00:00
Revert cuz golang :) messes up rand add full size
This commit is contained in:
11
nset.go
11
nset.go
@ -38,13 +38,9 @@ type NSet[T IntsIf] struct {
|
|||||||
|
|
||||||
func (n *NSet[T]) Add(x T) {
|
func (n *NSet[T]) Add(x T) {
|
||||||
|
|
||||||
//NOTE: The inlines here improve addition times by a good amount (several seconds)
|
bucket := n.GetBucketFromValue(x)
|
||||||
//NOTE: inline of n.GetBucketFromValue(x)
|
|
||||||
bucket := &n.Buckets[BucketType(x>>n.shiftAmount)]
|
|
||||||
|
|
||||||
//NOTE: This is an inline of n.GetStorageUnitIndex(x)
|
|
||||||
unitIndex := uint32(((x << BucketIndexingBits) >> BucketIndexingBits) / StorageTypeBits)
|
|
||||||
|
|
||||||
|
unitIndex := n.GetStorageUnitIndex(x)
|
||||||
if unitIndex >= bucket.StorageUnitCount {
|
if unitIndex >= bucket.StorageUnitCount {
|
||||||
|
|
||||||
storageUnitsToAdd := unitIndex - bucket.StorageUnitCount + 1
|
storageUnitsToAdd := unitIndex - bucket.StorageUnitCount + 1
|
||||||
@ -54,8 +50,7 @@ func (n *NSet[T]) Add(x T) {
|
|||||||
bucket.StorageUnitCount += storageUnitsToAdd
|
bucket.StorageUnitCount += storageUnitsToAdd
|
||||||
}
|
}
|
||||||
|
|
||||||
//NOTE: Inline of n.GetBitMask(x)
|
bucket.Data[unitIndex] |= n.GetBitMask(x)
|
||||||
bucket.Data[unitIndex] |= 1 << (((x << BucketIndexingBits) >> BucketIndexingBits) % StorageTypeBits)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NSet[T]) Remove(x T) {
|
func (n *NSet[T]) Remove(x T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user