Skip to content

Dictionary

Hyomoto edited this page Jun 13, 2021 · 3 revisions
Jump To Go Back Methods Variables

Dictionary( )

Implements: HashMap

Creates a dictionary-type structure. Unlike a hash table, a dictionary can be searched for a nearest match as well as specific entries, as well as iterate through entries forwards or backwards.

Methods

Jump To top set unset lookup peek poke first last next previous search keys_to_array from_JSON size clear

set( key, value )

Returns: self

Throws: InvalidArgumentType

Name Type Purpose
key string The key used to look up the value
value mixed The value to assign to the key

Sets the given key in the dictionary to the provided value. If the key is not a string, InvalidArgumentType will be thrown.


unset( key )

Returns: self

Throws: InvalidArgumentType, ValueNotFound

Name Type Purpose
key string The key to remove

Removes the given key from the dictionary. If the key didn't exist, ValueNotFound will be thrown. If the key was not a string, InvalidArgumentType is thrown.


lookup( key )

Returns: mixed

Throws: InvalidArgumentType, ValueNotFound

Name Type Purpose
key string The key to look up

Looks up the given key in the dictionary and returns its value. If the key is not a string, InvalidArgumentType is thrown. If the value does not exist, ValueNotFound will be thrown.


peek( )

Returns: mixed or ValueNotFound

Name Type Purpose
None

Returns the value of the last read key, or ValueNotFound if it doesn't exist.


poke( value )

Returns: self

Throws: ValueNotFound

Name Type Purpose
value mixed The value to assign

Sets the last read key to the provided value. If there was no last value read, ValueNotFound is thrown.


first( )

Returns: mixed or ValueNotFound

Name Type Purpose
None

Returns the next key after the last key searched, or ValueNotFound if it doesn't exist.


last( )

Returns: mixed or ValueNotFound

Name Type Purpose
None

Returns the previous key after the last key searched, or ValueNotFound if it doesn't exist.


next( )

Returns: mixed or ValueNotFound

Name Type Purpose
None

Returns the next key after the last key searched, or ValueNotFound if it doesn't exist.


previous( )

Returns: mixed or ValueNotFound

Name Type Purpose
None

Returns the previous key after the last key searched, or ValueNotFound if it doesn't exist.


search( pattern )

Returns: string or ValueNotFound

Name Type Purpose
pattern string The search pattern to look for

Searches for the nearest key to the given search pattern.


keys_to_array( )

Returns: array

Name Type Purpose
None

Returns the keys in the dictionary formatted as an array.


from_JSON( JSON_string )

Returns: self

Throws: InvalidArgumentType, UnexpectedTypeMismatch

Name Type Purpose
JSON_string string The string to convert into a dictionary

Takes the provided string and uses it to populate the dictionary. If a string is not provided, InvalidArgumentType is thrown. If the string does not convert into a dictionary UnexpectedTypeMismatch will be thrown.


size( )

Returns: mixed

Name Type Purpose
None

Returns the number of entries in the dictionary.


clear( )

Name Type Purpose
None

Empties the hash table


Variables

Jump To top
Name Type Initial Purpose
__Content struct {} The internal struct which holds the key/value pairs.
__Keys [ArrayList](arraylist) new ArrayList().order() An ordered list of all the keys in the dictionary.
__Last int undefined The last key that was looked up in the dictionary.
Clone this wiki locally