-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read from readonly memtable and refactor the priority queue for merge
- Loading branch information
1 parent
5b7a764
commit 8a95b2d
Showing
4 changed files
with
86 additions
and
87 deletions.
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 |
---|---|---|
@@ -1 +1,45 @@ | ||
package core | ||
|
||
type Item struct { | ||
SortKey string | ||
SSTableID int | ||
BlockID int | ||
EntryID int | ||
Index int | ||
} | ||
|
||
type PriorityQueue []*Item | ||
|
||
func (mpq PriorityQueue) Len() int { | ||
return len(mpq) | ||
} | ||
|
||
func (mpq PriorityQueue) Less(i, j int) bool { | ||
if mpq[i].SortKey == mpq[j].SortKey { | ||
return mpq[i].SSTableID > mpq[j].SSTableID | ||
} | ||
return mpq[i].SortKey < mpq[j].SortKey | ||
} | ||
|
||
func (pq PriorityQueue) Swap(i, j int) { | ||
pq[i], pq[j] = pq[j], pq[i] | ||
pq[i].Index = i | ||
pq[j].Index = j | ||
} | ||
|
||
func (pq *PriorityQueue) Push(x any) { | ||
n := len(*pq) | ||
item := x.(*Item) | ||
item.Index = n | ||
*pq = append(*pq, item) | ||
} | ||
|
||
func (pq *PriorityQueue) Pop() any { | ||
old := *pq | ||
n := len(old) | ||
item := old[n-1] | ||
old[n-1] = nil // avoid memory leak | ||
item.Index = -1 // for safety | ||
*pq = old[0 : n-1] | ||
return item | ||
} |
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
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
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