要素にキーを関連付けるコレクションの抽象パラメータ化クラス。
説明
注意事項
| self の efficient-size を取得または設定します。 |
| コレクションが空かどうかを調べます。 |
| キーのデータ型を返します。 |
| コレクションの要素数を返します。 |
| すべての要素を削除します。 |
| コレクションのクローンを返します。 |
| フィルタ操作内で要素を使って要素自体をフィルタリングします。 |
| (フィルタ操作内で要素を使って) クローンの要素が選別された、コレクションのクローンを返します。 |
| フィルタ操作でキーを使って要素をフィルタリングします。 |
| (フィルタ操作内でキーを使って) 要素が選別された、コレクションのクローンを返します。 |
| 特定の要素を返します。 |
| key でインデックス付けされた要素と、示された要素が見つかったかどうかを示すブール値を返します。 |
| 特定のキーを返します。 |
| 特定のキーと、示された要素が見つかったかどうかを示すブール値を返します。 |
| キーが存在するかどうかを調べます。 |
| コレクションの各キーを含む |
| 要素を削除します。 |
| 要素の値を設定します。 |
self の efficient-size を取得または設定します。
説明
効率的に機能するサイズです。このアクセッサは実装ごとに定義されますが、一般に下位のデータ構造のサイズを反映します。割り当てサイズを超えて拡張する場合、下位のデータ構造を新しく割り当て、古いデータ構造からデータをコピーする必要があります。ただし、この処理は
効率的でないと見なされます。
注意事項
コレクションが空かどうかを調べます。
戻り値
例
| 例 | |
|| Declare and initialize an empty hash table.
{let my-table:{HashTable-of int, String} =
{new {HashTable-of int, String}}}
|| Check if the hash table is empty and display an
|| appropriate message.
{if my-table.empty? then
{text The hash table is empty!}
else
{text The hash table has elements!}
}
|
| 例 | |
|| Declare and initialize a hash table with
|| int keys and String elements.
{let my-table:{HashTable-of int, String} =
{new {HashTable-of int, String},
1, "apple"
}
}
|| Check if the hash table is empty and display an
|| appropriate message.
{if my-table.empty? then
{text The hash table is empty!}
else
{text The hash table has elements!}
}
|
キーのデータ型を返します。
戻り値
例
| 例 | |
{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 the data type of key in price.
price.key-type
}
|
コレクションの要素数を返します。
戻り値
例
| 例 | |
{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.}
}
|
注意事項
すべての要素を削除します。
説明
例
| 例 | |
{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?}}
}
|
コレクションのクローンを返します。
戻り値
説明
例
| 例 | |
{value
|| Declare and initialize set-1 (the original set).
let set-1:{Set-of String} =
{new {Set-of String}, "apple", "banana", "cherry"}
|| Initialize set-2 with a clone of the contents of
|| set-1.
let set-2:{Set-of String} = {set-1.clone}
|| Use a VBox to display the contents of set-2.
|| Iterate over the contents of set-2, adding them
|| to the VBox. Then display the VBox.
let message:VBox = {VBox}
{for each-element:String in set-2 do
{message.add each-element}
}
message
}
|
注意事項
注意事項
フィルタ操作内で要素を使って要素自体をフィルタリングします。
戻り値
説明
例
| 例 | |
{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"
}
|| Filter elements that begin with the
|| letter 'd'.
{my-table.filter
{proc {str:String}:bool
{return str[0] != 'd'}
}
}
|| Use a VBox to display the contents of my-table.
|| Add each element to the VBox and then display it.
let message:VBox = {VBox}
{for each-element:String in my-table do
{message.add each-element}
}
message
|| Note that the order of the elements in a hash
|| table is arbitrary.
}
|
(フィルタ操作内で要素を使って) クローンの要素が選別された、コレクションのクローンを返します。
戻り値
説明
例
| 例 | |
{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.
}
|
注意事項
フィルタ操作でキーを使って要素をフィルタリングします。
説明
例
| 例 | |
{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
}
|| Filter elements whose keys begin with 'a'.
{quantity.filter-keys
{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 quantity do
{message.add each-element}
}
message
|| Note that the order of the elements in a hash
|| table is arbitrary.
}
|
(フィルタ操作内でキーを使って) 要素が選別された、コレクションのクローンを返します。
戻り値
説明
例
| 例 | |
{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.
}
|
注意事項
特定の要素を返します。
戻り値
例外のスロー
そのような要素が存在しない場合は、説明
例
| 例 | |
{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 for the presence of "banana" and "cherry",
|| showing how [] syntax can be used to call "get"
|| methods.
{text The price of bananas is {price.get "banana"},
the price of cherries is {value price["cherry"]}.}
|| Note that the order of the elements in a hash
|| table is arbitrary.
}
|
key でインデックス付けされた要素と、示された要素が見つかったかどうかを示すブール値を返します。
戻り値
特定のキーを返します。
戻り値
説明
例
| 例 | |
|| 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 method to get the original keys.
The hash table contains prices for...
{price.get-key "apple"}
{price.get-key "banana"}
{price.get-key "cherry"}
|
特定のキーと、示された要素が見つかったかどうかを示すブール値を返します。
戻り値
説明
例
| 例 | |
|| 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"}
|
注意事項
キーが存在するかどうかを調べます。
戻り値
例
| 例 | |
{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.}
}
}
|
コレクションの各キーを含む
戻り値
説明
例
| 例 | |
{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.
}
|
注意事項
注意事項
要素を削除します。
説明
例
| 例 | |
{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.
}
|
注意事項
要素の値を設定します。
説明
例
| 例 | |
![]() | |
{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.
}
|
注意事項