mirror of
https://github.com/bloeys/nset.git
synced 2025-12-29 14:28:20 +00:00
Copy function
This commit is contained in:
19
nset.go
19
nset.go
@ -149,6 +149,25 @@ func (n *NSet[T]) String() string {
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func (n *NSet[T]) Copy() *NSet[T] {
|
||||
|
||||
newSet := NewNSet[T]()
|
||||
for i := 0; i < len(n.Buckets); i++ {
|
||||
|
||||
b := &n.Buckets[i]
|
||||
newB := &newSet.Buckets[i]
|
||||
|
||||
newB.StorageUnitCount = b.StorageUnitCount
|
||||
newB.Data = make([]StorageType, len(b.Data))
|
||||
|
||||
copy(newB.Data, b.Data)
|
||||
}
|
||||
|
||||
newSet.StorageUnitCount = n.StorageUnitCount
|
||||
return newSet
|
||||
|
||||
}
|
||||
|
||||
func NewNSet[T IntsIf]() *NSet[T] {
|
||||
|
||||
n := &NSet[T]{
|
||||
|
||||
Reference in New Issue
Block a user