Skip to content

Commit

Permalink
Grow.
Browse files Browse the repository at this point in the history
Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
  • Loading branch information
ncruces committed Sep 25, 2024
1 parent cc82346 commit 24ef2a5
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions internal/descriptor/table.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package descriptor

import "math/bits"
import (
"math/bits"
"slices"
)

// Table is a data structure mapping 32 bit descriptor to items.
//
Expand Down Expand Up @@ -40,16 +43,10 @@ func (t *Table[Key, Item]) Len() (n int) {
// grow grows the table by n * 64 items.
func (t *Table[Key, Item]) grow(n int) {
total := len(t.masks) + n
if total > cap(t.masks) {
t.masks = append(t.masks, make([]uint64, n)...)
}
t.masks = t.masks[:total]
t.masks = slices.Grow(t.masks, n)[:total]

total = len(t.items) + n*64
if total > cap(t.items) {
t.items = append(t.items, make([]Item, n*64)...)
}
t.items = t.items[:total]
t.items = slices.Grow(t.items, n*64)[:total]
}

// Insert inserts the given item to the table, returning the key that it is
Expand Down

0 comments on commit 24ef2a5

Please sign in to comment.