Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func RankReposition(newPosition int, siblings List) {
- // No siblings, we take the middle spot
- if len(siblings) == 0 {
- return midWay // 2^63?
- }
- // Want to be the first one? Take the lowest rank and stand before it
- if newPosition == 0 {
- result = siblings.first.rank - windowSize
- if result < 0 {
- return -1 // we need respreading
- }
- return result
- }
- // To be the last one, take the last rank, and stand after it.
- if newPosition >= len(siblings) {
- result = siblings.last.rank + windowSize
- if result > maxSize {
- return -1 // we need respreading
- }
- return result
- }
- // To be at position i, stay in the middle of i-1 and i.
- availableWindowSize = siblings[newPosition].rank - siblings[newPosition-1].rank
- if availableWindowSize < 2 {
- return -1 // we need respreading
- }
- return siblings[newPosition].rank + (availableWindowSize / 2)
- }
Add Comment
Please, Sign In to add comment