Skip to content

Commit

Permalink
refine algorithm
Browse files Browse the repository at this point in the history
Signed-off-by: Bin Shi <binshi.bing@gmail.com>
  • Loading branch information
binshi-bing committed Apr 11, 2023
1 parent 8a17518 commit 9c7acff
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions pkg/tso/keyspace_group_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,10 +524,6 @@ func (kgm *KeyspaceGroupManager) updateKeyspaceGroupMembership(
} else {
sameMembership = false
kgm.keyspaceLookupTable.Store(newKeyspaces[j], groupID)
if keyspaceLookupTable == nil {
keyspaceLookupTable = make(map[uint32]struct{})
}
keyspaceLookupTable[newKeyspaces[j]] = struct{}{}
j++
}
}
Expand All @@ -554,14 +550,15 @@ func (kgm *KeyspaceGroupManager) updateKeyspaceGroupMembership(
if keyspaceLookupTable == nil {
keyspaceLookupTable = make(map[uint32]struct{})
}
for i, j = 0, 0; i < oldLen && j < newLen; {
if oldKeyspaces[i] == newKeyspaces[j] {
keyspaceLookupTable[oldKeyspaces[i]] = struct{}{}
for i, j = 0, 0; i < oldLen || j < newLen; {
if i < oldLen && j < newLen && oldKeyspaces[i] == newKeyspaces[j] {
keyspaceLookupTable[newKeyspaces[j]] = struct{}{}
i++
j++
} else if oldKeyspaces[i] < newKeyspaces[j] {
} else if i < oldLen && j < newLen && oldKeyspaces[i] < newKeyspaces[j] || j == newLen {
i++
} else {
keyspaceLookupTable[newKeyspaces[j]] = struct{}{}
j++
}
}
Expand Down

0 comments on commit 9c7acff

Please sign in to comment.