Last active
August 11, 2018 18:55
-
-
Save lkrych/34e0c218355cf7558dfa86e0a141846c to your computer and use it in GitHub Desktop.
symbol table abstraction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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