From 920b23133974f80285d7fa42207fca841493eba7 Mon Sep 17 00:00:00 2001 From: HTHou Date: Mon, 29 Apr 2024 17:08:46 +0800 Subject: [PATCH] add sort bitmap --- .github/workflows/go.yml | 2 +- client/bitmap.go | 14 ++++++++++++++ client/tablet.go | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 0f675c3..b6a8d43 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -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 }} diff --git a/client/bitmap.go b/client/bitmap.go index 825a995..b82d121 100644 --- a/client/bitmap.go +++ b/client/bitmap.go @@ -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{ @@ -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 } diff --git a/client/tablet.go b/client/tablet.go index e150c68..7fe2e97 100644 --- a/client/tablet.go +++ b/client/tablet.go @@ -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] }