Skip to content

Commit

Permalink
add sort bitmap
Browse files Browse the repository at this point in the history
  • Loading branch information
HTHou committed Apr 29, 2024
1 parent 5df8640 commit 920b231
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
go: ['1.13', 'stable']
go: ['1.14', 'stable']
steps:

- name: Set up Go ${{ matrix.go }}
Expand Down
14 changes: 14 additions & 0 deletions client/bitmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ type BitMap struct {
}

var BitUtil = []byte{1, 2, 4, 8, 16, 32, 64, 128}
var UnmarkBitUtil = []byte{
0xFE, // 11111110
0xFD, // 11111101
0xFB, // 11111011
0xF7, // 11110111
0xEF, // 11101111
0xDF, // 11011111
0xBF, // 10111111
0x7F, // 01111111
}

func NewBitMap(size int) *BitMap {
bitMap := &BitMap{
Expand All @@ -38,6 +48,10 @@ func (b *BitMap) Mark(position int) {
b.bits[position/8] |= BitUtil[position%8]
}

func (b *BitMap) UnMark(position int) {
b.bits[position/8] &= UnmarkBitUtil[position%8]
}

func (b *BitMap) IsMarked(position int) bool {
return (b.bits[position/8] & BitUtil[position%8]) != 0
}
Expand Down
18 changes: 18 additions & 0 deletions client/tablet.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,24 @@ func (t *Tablet) Swap(i, j int) {
sortedSlice[i], sortedSlice[j] = sortedSlice[j], sortedSlice[i]
}
}
if t.bitMaps != nil {
for _, bitMap := range t.bitMaps {
if bitMap != nil {
isNilI := bitMap.IsMarked(i)
isNilJ := bitMap.IsMarked(j)
if isNilI {
bitMap.Mark(j)
} else {
bitMap.UnMark(j)
}
if isNilJ {
bitMap.Mark(i)
} else {
bitMap.UnMark(i)
}
}
}
}
t.timestamps[i], t.timestamps[j] = t.timestamps[j], t.timestamps[i]
}

Expand Down

0 comments on commit 920b231

Please sign in to comment.