Skip to content

Instantly share code, notes, and snippets.

@joschuck
Created January 28, 2015 19:49
Show Gist options
  • Select an option

  • Save joschuck/3a69b5a33461a48392a9 to your computer and use it in GitHub Desktop.

Select an option

Save joschuck/3a69b5a33461a48392a9 to your computer and use it in GitHub Desktop.
Binary Tree Operations
getIndex: (level, levelIndex) ->
return levelIndex + (1 << level) -1
getParentIndex: (i) ->
return (i - 1) // 2
getLeftChild: (i) ->
return 2*(i+1) - 1
getRightChild: (i) ->
return 2*(i+1)
getLevel: (i) ->
return Math.log(i+1) // Math.log(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment