Skip to content

Instantly share code, notes, and snippets.

@lkrych
Last active August 11, 2018 18:55
Show Gist options
  • Save lkrych/34e0c218355cf7558dfa86e0a141846c to your computer and use it in GitHub Desktop.
Save lkrych/34e0c218355cf7558dfa86e0a141846c to your computer and use it in GitHub Desktop.
symbol table abstraction
type SymbolTable struct {
data *BSTree
}
//adds or updates node with key "key"
func (st *SymbolTable) put(key string, val int) {
st.data.root = put(st.data.root, key, val)
}
//returns node with key "key"
func (st *SymbolTable) get(key string) *Node {
return get(st.data.root, key)
}
// checks if node with key "key" exists in symbol table
func (st *SymbolTable) contains(key string) bool {
return get(st.data.root, key) == nil
}
//returns an array of Nodes in sorted order
func (st *SymbolTable) keys() []Node {
return returnKeys(st.data.root)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment