Parameterized class for hash tables.
Description
Notes
Notes
Notes
| Initialize a |
| Initialize a |
| Gets or sets the efficient-size of self. |
| Returns the number of elements in the collection. |
| Removes all elements. |
| Returns a clone of the hash table. |
| Returns a clone of the collection, with elements filtered out (using the elements themselves in the filter operation). |
| Returns a clone of the collection, with elements filtered out (using the keys in the filter operation). |
| Returns the element indexed by key, along with a boolean that signifies whether the indicated element was found. |
| Returns a specific key, along with a boolean that signifies whether the indicated key was found. |
| Increases the structures that internally represent the hash table. |
| Check if a key exists. |
| Returns an |
| Called by the serialization code when a class instance is to be written. |
| Rehashes self. |
| Removes an element. |
| Sets the value of an element. |
| Returns an |
Initialize a
Initialize a
Description
Gets or sets the efficient-size of self.
Description
Returns the number of elements in the collection.
Returns
Example
| Example | |
{value
|| Declare and initialize a hash table with
|| String keys and int elements.
let price:{HashTable-of String, int} =
{new {HashTable-of String, int},
"apple", 56,
"banana", 87,
"cherry", 34
}
|| Display a message indicating the size of
|| the hash table.
{text There are {value price.size} elements in
the hash table.}
}
|
Notes
Removes all elements.
Example
| Example | |
{value
|| Declare and initialize a hash table with
|| int keys and String elements.
let my-table:{HashTable-of int, String} =
{new {HashTable-of int, String},
162094, "tom",
439853, "dick",
098627, "harry"
}
|| Clear the hash table.
{my-table.clear}
|| Check if the hash table is empty.
{text The assertion that the hash table is empty is...
{value my-table.empty?}}
}
|
Returns a clone of the hash table.
Returns
Description
Example
| Example | |
![]() | |
|| Declare and initialize a hash table with
|| String keys and int elements.
{let table-1:{HashTable-of int, String} =
{new {HashTable-of int, String},
162094, "tom",
439853, "dick",
098627, "harry"
}
}
|| Declare table-2 (a target hash table) and initialize it with
|| a copy of the contents of table-1.
{let table-2:{HashTable-of int, String} = {table-1.clone}}
|| Use a VBox to display the contents of table-2.
|| For each key in table-2 add an HBox to the VBox.
|| The HBox contains the relevant key and element.
|| Then display the VBox.
{let message:VBox = {VBox}}
{for key i:int in table-2 do
{message.add {HBox i, " ", {table-2.get i}}}
}
{value message}
|
Notes
Returns a clone of the collection, with elements filtered out (using the elements themselves in the filter operation).
Returns
Description
Example
| Example | |
{value
|| Declare and initialize a hash table with
|| int keys and String elements.
let my-table-1:{HashTable-of int, String} =
{new {HashTable-of int, String},
162094, "tom",
439853, "dick",
098627, "harry"
}
|| Create a clone my-table-2 that contains the elements
|| of my-table-1 with strings that begin with the letter
|| 'd' filtered out.
let my-table-2:{HashTable-of int, String} =
{my-table-1.filter-clone
{proc {str:String}:bool
{return str[0] != 'd'}
}
}
|| Use a VBox to display the contents of my-table-2.
|| Iterate over the contents of my-table-2, adding
|| them to the VBox. Then display the VBox.
let message:VBox = {VBox}
{for each-element:String in my-table-2 do
{message.add each-element}
}
message
|| Note that the order of the elements in a hash
|| table is arbitrary.
}
|
Notes
Returns a clone of the collection, with elements filtered out (using the keys in the filter operation).
Returns
Description
Example
| Example | |
{value
|| Declare and initialize a hash table with
|| String keys and int elements.
let quantity:{HashTable-of String, int} =
{new {HashTable-of String, int},
"apple", 3,
"banana", 0,
"cherry", 8
}
|| Create a clone that contains the elements of the
|| original with keys that begin with the letter
|| 'a' filtered out.
let new-quantity:{HashTable-of String, int} =
{quantity.filter-keys-clone
{proc {str:String}:bool
{return str[0] != 'a'}
}
}
|| Use a VBox to display the contents of quantity.
|| For each key in quantity, add the key to the VBox.
|| Then display the VBox.
let message:VBox = {VBox}
{for key each-element:String in new-quantity do
{message.add each-element}
}
message
|| Note that the order of the elements in a hash
|| table is arbitrary.
}
|
Notes
Returns the element indexed by key, along with a boolean that signifies whether the indicated element was found.
Returns
Returns a specific key, along with a boolean that signifies whether the indicated key was found.
Returns
Description
Example
| Example | |
|| Declare and initialize a hash table with
|| String keys and int elements.
{let price:{HashTable-of String, int} =
{new {HashTable-of String, int},
"apple", 56,
"banana", 87,
"cherry", 34
}
}
|| Use the get-key-if-exists method to check for the
|| presence of keys.
The hash table contains prices for...
{price.get-key-if-exists "apple"}
{price.get-key-if-exists "banana"}
{price.get-key-if-exists "pear"}
{price.get-key-if-exists "cherry"}
{price.get-key-if-exists "orange"}
|
Notes
Increases the structures that internally represent the hash table.
Description
Check if a key exists.
Returns
Example
| Example | |
{value
|| Declare and initialize a hash table with
|| String keys and int elements.
let price:{HashTable-of String, int} =
{new {HashTable-of String, int},
"apple", 56,
"banana", 87,
"cherry", 34
}
|| Check if there is an element with the
|| key "banana" in the collection "price".
{if {price.key-exists? "banana"} then
{text It is there!}
else
{text It is not there.}
}
}
|
Returns an
Returns
Description
Example
| Example | |
{value
|| Declare and initialize a hash table with
|| int keys and String elements.
let my-table:{HashTable-of int, String} =
{new {HashTable-of int, String},
162094, "tom",
439853, "dick",
098627, "harry"
}
|| Create an Iterator-of from the set.
let my-iterator:{Iterator-of int} =
{my-table.keys-to-Iterator}
|| Use a VBox to display the contents of my-iterator.
|| Iterate over the contents of my-iterator, adding
|| them to the VBox. Then display the VBox.
let message:VBox = {VBox}
{for each-element:int in my-iterator do
{message.add each-element}
}
message
|| Note that the order of the elements in a hash
|| table is arbitrary.
}
|
Notes
Notes
Called by the serialization code when a class instance is to be written.
Description
Notes
Rehashes self.
Removes an element.
Description
Example
| Example | |
{value
|| Declare and initialize a hash table with
|| String keys and int elements.
let price:{HashTable-of String, int} =
{new {HashTable-of String, int},
"apple", 56,
"banana", 87,
"cherry", 34
}
|| Remove the element at key "banana".
{price.remove "banana"}
|| Use a VBox to display the contents of price.
|| For each key in price, add a string to the VBox.
|| The string contains the relevant key and element.
|| Then display the VBox.
let message:VBox = {VBox}
{for key each-element:String in price do
{message.add each-element & " " & {price.get each-element}}
}
message
|| Note that the order of the elements in a hash
|| table is arbitrary.
}
|
Notes
Sets the value of an element.
Description
Example
| Example | |
![]() | |
{value
|| Declare and initialize a hash table with
|| String keys and int elements.
let price:{HashTable-of String, int} =
{new {HashTable-of String, int},
"apple", 56,
"banana", 87,
"cherry", 34
}
|| Change the element at key "banana".
{price.set "banana", 72}
|| Add an element for "pear".
{price.set "pear", 62}
|| Use a VBox to display the contents of price.
|| For each key in price, add a string to the VBox.
|| The string contains the relevant key and element.
|| Then display the VBox.
let message:VBox = {VBox}
{for key each-element:String in price do
{message.add each-element & " " & {price.get each-element}}
}
message
|| Note that the order of the elements in a hash
|| table is arbitrary.
}
|
Notes
Returns an
Returns
Example
| Example | |
{value || Declare and initialize a hash table with
|| String keys and int elements
let h:{HashTable-of int, String} =
{new {HashTable-of int, String},
162094, "tom",
439853, "dick",
098627, "harry"
}
|| Create an Iterator-of from the hash table.
let my-iterator:{Iterator-of String} =
{h.to-Iterator}
|| Use a VBox to display the contents of my-iterator.
|| Iterate over the contents of my-iterator, adding
|| them to the VBox. Then display the VBox.
let message:VBox = {VBox}
{for each-element:String in my-iterator do
{message.add each-element}
}
message
}
|
Notes
Notes