Skip to content

Commit

Permalink
Merge branch 'main' into simplify-csv
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmo314 authored Feb 11, 2024
2 parents 1e54f25 + 78233f9 commit 1994d0e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
11 changes: 5 additions & 6 deletions pkg/appendable/index_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (i *IndexFile) IsEmpty() (bool, error) {
}

func (i *IndexFile) IndexFieldNames() ([]string, error) {
var fieldNames []string
uniqueFieldNames := make(map[string]bool)

mp := i.tree
Expand All @@ -118,15 +119,13 @@ func (i *IndexFile) IndexFieldNames() ([]string, error) {
return nil, fmt.Errorf("failed to unmarshal metadata: %w", err)
}

uniqueFieldNames[metadata.FieldName] = true
if _, ok := uniqueFieldNames[metadata.FieldName]; !ok {
uniqueFieldNames[metadata.FieldName] = true
fieldNames = append(fieldNames, metadata.FieldName)
}
mp = next
}

var fieldNames []string
for fieldName := range uniqueFieldNames {
fieldNames = append(fieldNames, fieldName)
}

return fieldNames, nil
}

Expand Down
27 changes: 13 additions & 14 deletions pkg/btree/bptree.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,27 @@ func (t *BPTree) traverse(key []byte, node *BPTreeNode, ptr MemoryPointer) ([]Tr
if node.leaf() {
return []TraversalRecord{{node: node, ptr: ptr}}, nil
}
for i, k := range node.Keys {
if bytes.Compare(key, k.Value) < 0 {
child, err := t.readNode(node.Pointer(i))
if err != nil {
return nil, err
}
path, err := t.traverse(key, child, node.Pointer(i))
if err != nil {
return nil, err
}
return append(path, TraversalRecord{node: node, index: i, ptr: ptr}), nil

// binary search node.Keys to find the first key greater than or equal to key
low, high := 0, len(node.Keys)
for low < high {
mid := (low + high) / 2
if bytes.Compare(key, node.Keys[mid].Value) < 0 {
high = mid
} else {
low = mid + 1
}
}
child, err := t.readNode(node.Pointer(-1))
// low == high
child, err := t.readNode(node.Pointer(low))
if err != nil {
return nil, err
}
path, err := t.traverse(key, child, node.Pointer(-1))
path, err := t.traverse(key, child, node.Pointer(low))
if err != nil {
return nil, err
}
return append(path, TraversalRecord{node: node, index: len(node.Keys), ptr: ptr}), nil
return append(path, TraversalRecord{node: node, index: low, ptr: ptr}), nil
}

func (t *BPTree) Insert(key ReferencedValue, value MemoryPointer) error {
Expand Down

0 comments on commit 1994d0e

Please sign in to comment.