package iskra import ( "git.smesh.lol/iskradb/lattice" "slices" ) // BulkEntry represents a keyed record reference for bulk operations. // RecIdx is the record index in the iskradb tree (was MetaIdx+LexIdx pair). type BulkEntry struct { Key lattice.Key RecIdx uint32 } // BulkLoad is a no-op: iskradb manages its own B-tree balancing. // Kept for API compatibility. func (t *Tree) BulkLoad(entries []BulkEntry) {} // Repack is a no-op: iskradb manages its own B-tree compaction. // Kept for API compatibility. func (t *Tree) Repack() {} // ExtractEntries returns all entries in the tree across all three branches, // in ascending key order within each branch. func (t *Tree) ExtractEntries() []BulkEntry { var entries []BulkEntry for b := 0; b < 3; b++ { entries = append(entries, t.extractBranchEntries(b)...) } return entries } func (t *Tree) extractBranchEntries(branch int) []BulkEntry { var entries []BulkEntry for recIdx, key := range t.db.RecKey { if int(t.db.GetRecord(recIdx).Branch) == branch { entries = append(entries, BulkEntry{Key: key, RecIdx: recIdx}) } } return entries } func SortEntries(entries []BulkEntry) { slices.SortFunc(entries, func(a, b BulkEntry) int { if a.Key[0] < b.Key[0] || (a.Key[0] == b.Key[0] && a.Key[1] < b.Key[1]) { return -1 } if a.Key[0] > b.Key[0] || (a.Key[0] == b.Key[0] && a.Key[1] > b.Key[1]) { return 1 } return 0 }) } // Depth returns the depth of the noun branch tree (proxy for overall tree depth). func (t *Tree) Depth() int { // Estimate depth from node count: depth ≈ log3(nodeCount) n := t.db.NodeCount() d := 0 for n > 1 { n /= 3 d++ } return d }