mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 09:05:55 +00:00
add PutContainerValues to Containers interface to prevent re-allocation of containers
This commit is contained in:
parent
0bed8de647
commit
0757a84f69
3 changed files with 31 additions and 5 deletions
|
|
@ -47,6 +47,25 @@ func (btc *BTreeContainers) Put(key uint64, c *container) {
|
|||
btc.tree.Set(key, c)
|
||||
}
|
||||
|
||||
func (btc *BTreeContainers) PutContainerValues(key uint64, containerType byte, n int, mapped bool) {
|
||||
f := func(oldV *container, exists bool) (*container, bool) {
|
||||
// update the existing container
|
||||
if exists {
|
||||
oldV.containerType = containerType
|
||||
oldV.n = n
|
||||
oldV.mapped = mapped
|
||||
return oldV, true
|
||||
}
|
||||
return &container{
|
||||
containerType: containerType,
|
||||
n: n,
|
||||
mapped: mapped,
|
||||
}, true
|
||||
}
|
||||
|
||||
btc.tree.Put(key, f)
|
||||
}
|
||||
|
||||
func (btc *BTreeContainers) Remove(key uint64) {
|
||||
btc.tree.Delete(key)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,9 @@ func (slc *SkipListContainers) Put(key uint64, c *container) {
|
|||
slc.list.Set(key, c)
|
||||
}
|
||||
|
||||
func (slc *SkipListContainers) PutContainerValues(key uint64, containerType byte, n int, mapped bool) {
|
||||
}
|
||||
|
||||
func (slc *SkipListContainers) Remove(key uint64) {
|
||||
slc.list.Remove(key)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,6 +70,10 @@ type Containers interface {
|
|||
// Put adds the container at key.
|
||||
Put(key uint64, c *container)
|
||||
|
||||
// PutContainerValues updates an existing container at key.
|
||||
// If a container does not exist for key, a new one is allocated.
|
||||
PutContainerValues(key uint64, containerType byte, n int, mapped bool)
|
||||
|
||||
// Remove takes the container at key out.
|
||||
Remove(key uint64)
|
||||
|
||||
|
|
@ -631,11 +635,11 @@ func (b *Bitmap) UnmarshalBinary(data []byte) error {
|
|||
|
||||
// Descriptive header section: Read container keys and cardinalities.
|
||||
for i, buf := 0, data[headerSize:]; i < int(keyN); i, buf = i+1, buf[12:] {
|
||||
b.conts.Put(binary.LittleEndian.Uint64(buf[0:8]), &container{
|
||||
containerType: byte(binary.LittleEndian.Uint16(buf[8:10])),
|
||||
n: int(binary.LittleEndian.Uint16(buf[10:12])) + 1,
|
||||
mapped: true,
|
||||
})
|
||||
b.conts.PutContainerValues(
|
||||
binary.LittleEndian.Uint64(buf[0:8]),
|
||||
byte(binary.LittleEndian.Uint16(buf[8:10])),
|
||||
int(binary.LittleEndian.Uint16(buf[10:12]))+1,
|
||||
true)
|
||||
}
|
||||
opsOffset := headerSize + int(keyN)*12
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue