Guest User

Untitled

a guest
Jul 22nd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. func RankReposition(newPosition int, siblings List) {
  2. // No siblings, we take the middle spot
  3. if len(siblings) == 0 {
  4. return midWay // 2^63?
  5. }
  6.  
  7. // Want to be the first one? Take the lowest rank and stand before it
  8. if newPosition == 0 {
  9. result = siblings.first.rank - windowSize
  10. if result < 0 {
  11. return -1 // we need respreading
  12. }
  13. return result
  14. }
  15.  
  16. // To be the last one, take the last rank, and stand after it.
  17. if newPosition >= len(siblings) {
  18. result = siblings.last.rank + windowSize
  19. if result > maxSize {
  20. return -1 // we need respreading
  21. }
  22. return result
  23. }
  24.  
  25. // To be at position i, stay in the middle of i-1 and i.
  26. availableWindowSize = siblings[newPosition].rank - siblings[newPosition-1].rank
  27. if availableWindowSize < 2 {
  28. return -1 // we need respreading
  29. }
  30.  
  31. return siblings[newPosition].rank + (availableWindowSize / 2)
  32. }
Add Comment
Please, Sign In to add comment