25 lines
546 B
Go
25 lines
546 B
Go
|
package mdb
|
||
|
|
||
|
type collectionState[T any] struct {
|
||
|
Version uint64
|
||
|
Indices []indexState[T]
|
||
|
}
|
||
|
|
||
|
func (c *collectionState[T]) clone(version uint64) *collectionState[T] {
|
||
|
indices := make([]indexState[T], len(c.Indices))
|
||
|
for i := range indices {
|
||
|
indices[i] = c.Indices[i].clone()
|
||
|
}
|
||
|
return &collectionState[T]{
|
||
|
Version: version,
|
||
|
Indices: indices,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Add an index returning it's assigned ID.
|
||
|
func (c *collectionState[T]) addIndex(idx indexState[T]) uint64 {
|
||
|
id := uint64(len(c.Indices))
|
||
|
c.Indices = append(c.Indices, idx)
|
||
|
return id
|
||
|
}
|