-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a120349
commit 57462a6
Showing
4 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package btree | ||
|
||
import ( | ||
"github.com/kevmo314/appendable/pkg/metapage" | ||
"github.com/kevmo314/appendable/pkg/pagefile" | ||
"github.com/kevmo314/appendable/pkg/pointer" | ||
"io" | ||
) | ||
|
||
type BTree struct { | ||
MetaPage metapage.MetaPage | ||
PageFile pagefile.ReadWriteSeekPager | ||
|
||
Width uint16 | ||
} | ||
|
||
func (t *BTree) root() (*BTreeNode, pointer.MemoryPointer, error) { | ||
mp, err := t.MetaPage.Root() | ||
if err != nil { | ||
return nil, mp, err | ||
} | ||
|
||
root, err := t.readNode(mp.Offset) | ||
if err != nil { | ||
return nil, mp, err | ||
} | ||
|
||
return root, mp, nil | ||
} | ||
|
||
func (t *BTree) readNode(offset uint64) (*BTreeNode, error) { | ||
if _, err := t.PageFile.Seek(int64(offset), io.SeekStart); err != nil { | ||
return nil, err | ||
} | ||
|
||
node := &BTreeNode{Width: t.Width} | ||
buf := make([]byte, t.PageFile.PageSize()) | ||
|
||
if _, err := t.PageFile.Read(buf); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := node.UnmarshalBinary(buf); err != nil { | ||
return nil, err | ||
} | ||
|
||
return node, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package btree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package btree | ||
|
||
import ( | ||
"github.com/kevmo314/appendable/pkg/hnsw" | ||
"io" | ||
) | ||
|
||
type BTreeNode struct { | ||
Ids []hnsw.Id | ||
Vectors []hnsw.Point | ||
|
||
Pointers []uint64 | ||
Width uint16 | ||
} | ||
|
||
func (n *BTreeNode) Size() int64 { | ||
return 0 | ||
} | ||
|
||
// MarshalBinary TODO! | ||
func (n *BTreeNode) MarshalBinary() ([]byte, error) { | ||
b := []byte{} | ||
|
||
return b, nil | ||
} | ||
|
||
// UnmarshalBinary TODO! | ||
func (n *BTreeNode) UnmarshalBinary(buf []byte) error { | ||
return nil | ||
} | ||
|
||
func (n *BTreeNode) WriteTo(w io.Writer) (int64, error) { | ||
buf, err := n.MarshalBinary() | ||
if err != nil { | ||
return 0, err | ||
} | ||
m, err := w.Write(buf) | ||
return int64(m), err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters