セットの抽象パラメータ化クラス。
説明
注意事項
注意事項
| self の efficient-size を取得または設定します。 |
| コレクションが空かどうかを調べます。 |
| コレクションの要素数。 |
| すべての要素を削除します。 |
| コレクションのクローンを返します。 |
| 1 つのセットとその他の複数のセットの間の差を形成します。 |
| 2 つ以上のセット間の差を含むクローンを返します。 |
| 2つのセットが等しいかどうかを判断します。 |
| 要素をフィルタリングします。 |
| 要素が選別された、コレクションのクローンを返します。 |
| 特定の要素に等しいセット内の要素を返します。 |
| 特定の要素に等しいセット内の要素、および示された要素が見つかったかどうかを示すブール値を返します。 |
| 要素を追加します。 |
| 要素が 1 つ追加された、セットのクローンを返します。 |
| 2 つ以上のセットの交点を形成します。 |
| 2 つ以上のセットの交点を含むクローンを返します。 |
| 要素がセットに含まれているかどうかを判断します。 |
| クラス インスタンスが書き込まれるときに、シリアル化コードで呼び出されます。 |
| 要素を削除します。 |
| 要素が 1 つ削除された、セットのクローンを返します。 |
| コレクションの各要素を含む |
| 2 つ以上のセットの結合を形成します。 |
| 2 つ以上のセットの結合を含むクローンを返します。 |
説明
self の efficient-size を取得または設定します。
説明
効率的に機能するサイズです。このアクセッサは実装ごとに定義されますが、一般に下位のデータ構造のサイズを反映します。割り当てサイズを超えて拡張する場合、下位のデータ構造を新しく割り当て、古いデータ構造からデータをコピーする必要があります。ただし、この処理は
効率的でないと見なされます。
注意事項
コレクションが空かどうかを調べます。
戻り値
例
| 例 | |
{value
|| Declare and initialize an empty set.
let my-set:{Set-of String} =
{new {Set-of String}}
|| Check if the set is empty and display an
|| appropriate message.
{if my-set.empty? then
{text The set is empty!}
else
{text The set has elements!}
}
}
|
| 例 | |
{value
|| Declare and initialize a set with elements.
let my-set:{Set-of String} =
{new {Set-of String}, "apple"}
|| Check if the set is empty and display an
|| appropriate message.
{if my-set.empty? then
{text The set is empty!}
else
{text The set has elements!}
}
}
|
注意事項
コレクションの要素数。
戻り値
説明
例
| 例: セットの要素を数える | |
{value
|| Declare and initialize s (a set).
let s:{Set-of String} =
{new {Set-of String}, "apple", "banana", "cherry"}
|| Display the size of the set.
s.size
}
|
すべての要素を削除します。
例
| 例: clear : セットを空にする | |
{value
|| Declare and initialize my-set (a set of strings).
let my-set:{Set-of String} =
{new {Set-of String}, "apple", "banana", "cherry"}
|| Clear the set.
{my-set.clear}
|| Check if the set is empty.
{text The assertion that the set is empty is...
{value my-set.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
}
|
注意事項
注意事項
1 つのセットとその他の複数のセットの間の差を形成します。
説明
例
| 例: difference:二つ以上のセットの相違を形成する | |
{value
|| Declare and initialize set-1 (a set).
let set-1:{Set-of String} =
{new {Set-of String}, "apple", "banana", "cherry"}
|| Declare and initialize set-2 (a set).
let set-2:{Set-of String} =
{new {Set-of String}, "apple", "plum", "peach"}
|| Form the difference between the elements of
|| set-1 and set-2.
{set-1.difference set-2}
|| Use a VBox to display the contents of set-1.
|| Iterate over the contents of set-1, adding them
|| to the VBox. Then display the VBox.
let message:VBox = {VBox}
{for each-element:String in set-1 do
{message.add each-element}
}
message
}
|
2 つ以上のセット間の差を含むクローンを返します。
戻り値
説明
例
| 例: difference-clone を使用してNセットの相違を含む新しいセットを形成する。 | |
{value
|| Declare and initialize set-1 (a set).
let set-1:{Set-of String} =
{new {Set-of String}, "apple", "banana", "cherry"}
|| Declare and initialize set-2 (a set).
let set-2:{Set-of String} =
{new {Set-of String}, "apple", "plum", "peach"}
|| Initialize set-3 with a clone of the contents
|| of set-1 intersected with the elements of
|| set-2.
let set-3:{Set-of String} = {set-1.difference-clone set-2}
|| Use a VBox to display the contents of set-3.
|| Iterate over the contents of set-3, adding them
|| to the VBox. Then display the VBox.
let message:VBox = {VBox}
{for each-element:String in set-3 do
{message.add each-element}
}
message
}
|
注意事項
2つのセットが等しいかどうかを判断します。
戻り値
説明
例
| 例: セットが同等であるかどうかテストする | |
|| Declare and initialize set-1 and set-2, two sets
|| with identical contents.
{let set-1:{Set-of String} =
{new {Set-of String}, "apple", "banana", "cherry"}
}
{let set-2:{Set-of String} =
{new {Set-of String}, "apple", "banana", "cherry"}
}
|| Output a message indicating if set-1 and set-2
|| are equal.
The assertion that the sets are equal is...
{set-1.equal? set-2}
|| Remove an element from set-1.
{set-1.remove "banana"}
|| Output a message indicating if set-1 and set-2 are
|| equal
After removing an element, the assertion is...
{set-1.equal? set-2}
|
要素をフィルタリングします。
戻り値
説明
例
| 例 | |
{value
|| Declare and initialize my-set (a set of strings).
let my-set:{Set-of String} =
{new {Set-of String}, "apple", "banana", "cherry"}
|| Filter elements that begin with the
|| letter 'a'.
{my-set.filter
{proc {str:String}:bool
{return str[0] != 'a'}
}
}
|| Use a VBox to display the contents of my-set.
|| Iterate over the contents of my-set, adding them
|| to the VBox. Then display the VBox.
let message:VBox = {VBox}
{for each-element:String in my-set do
{message.add each-element}
}
message
}
|
注意事項
要素が選別された、コレクションのクローンを返します。
戻り値
説明
例
| 例 | |
{value
|| Declare and initialize set-1 (a set).
let set-1:{Set-of String} =
{new {Set-of String}, "apple", "banana", "cherry"}
|| Create a clone set-2 that contains the elements
|| of set-1 with strings that begin with the letter
|| 'a' filtered out.
let set-2:{Set-of String} =
{set-1.filter-clone
{proc {str:String}:bool
{return str[0] != 'a'}
}
}
|| 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}
}
{value message}
}
|
注意事項
注意事項
特定の要素に等しいセット内の要素を返します。
戻り値
説明
例
| 例: get-member: 要素がセットの中に入っているかどうかのチェック | |
|| Declare and initialize a set with String members
{let fruit:{Set-of String} =
{new {Set-of String}, "apple", "banana", "cherry"}
}
|| Use the get-member method to check for the presence
|| of elements.
The set contains the following members...
{fruit.get-member "apple"}
{fruit.get-member "banana"}
{fruit.get-member "cherry"}
|
注意事項
特定の要素に等しいセット内の要素、および示された要素が見つかったかどうかを示すブール値を返します。
戻り値
説明
例
| 例: get-member-if-exists を使ってセットの要素を返す | |
|| Declare and initialize a set with String members
{let fruit:{Set-of String} =
{new {Set-of String}, "apple", "banana", "cherry"}
}
|| Use the get-member-if-exists method to check for the presence
|| of elements.
The set contains the following members...
{fruit.get-member-if-exists "apple"}
{fruit.get-member-if-exists "banana"}
{fruit.get-member-if-exists "pear"}
{fruit.get-member-if-exists "cherry"}
{fruit.get-member-if-exists "orange"}
|
要素を追加します。
説明
例
| 例: insert を使用し、セットの要素を追加する | |
{value
|| Declare and initialize my-set (a set).
let my-set:{Set-of String} =
{new {Set-of String}, "apple", "banana", "cherry"}
|| Add an element
{my-set.insert "orange"}
|| Use a VBox to display the contents of my-set.
|| Iterate over the contents of my-set, adding them
|| to the VBox. Then display the VBox.
let message:VBox = {VBox}
{for each-element:String in my-set do
{message.add each-element}
}
message
}
|
要素が 1 つ追加された、セットのクローンを返します。
戻り値
説明
例
| 例: insert-clone を使用してセットをクローンし、要素を一つ追加する | |
{value
|| Declare and initialize set-1 (a 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, adding the "peach" element.
let set-2:{Set-of String} = {set-1.insert-clone "peach"}
|| 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
}
|
注意事項
2 つ以上のセットの交点を形成します。
説明
例
| 例: intersection: 二つ以上のセットの倫理 AND を戻す | |
{value
|| Declare and initialize set-1 (a set).
let set-1:{Set-of String} =
{new {Set-of String}, "apple", "banana", "cherry"}
|| Declare and initialize set-2 (a set).
let set-2:{Set-of String} =
{new {Set-of String}, "apple", "plum", "peach"}
|| In set-1, form the intersection of the elements
|| in set-1 and set-2.
{set-1.intersection set-2}
|| Use a VBox to display the contents of set-1.
|| Iterate over the contents of set-1, adding them
|| to the VBox. Then display the VBox.
let message:VBox = {VBox}
{for each-element:String in set-1 do
{message.add each-element}
}
message
}
|
2 つ以上のセットの交点を含むクローンを返します。
戻り値
説明
例
| 例: intersection-clone: N セットの AND を含む新しいセットを作る | |
{value
|| Declare and initialize set-1 (a set).
let set-1:{Set-of String} =
{new {Set-of String}, "apple", "banana", "cherry"}
|| Declare and initialize set-2 (a set).
let set-2:{Set-of String} =
{new {Set-of String}, "apple", "plum", "peach"}
|| Initialize set-3 with a clone of the contents
|| of set-1 intersected with the elements of
|| set-2.
let set-3:{Set-of String} = {set-1.intersection-clone set-2}
|| Use a VBox to display the contents of set-3.
|| Iterate over the contents of set-3, adding them
|| to the VBox. Then display the VBox.
let message:VBox = {VBox}
{for each-element:String in set-3 do
{message.add each-element}
}
message
}
|
注意事項
要素がセットに含まれているかどうかを判断します。
戻り値
例
| 例: 要素がセットのメンバーかどうかを判断する | |
|| Declare and initialize s (a set).
{let s:{Set-of String} =
{new {Set-of String}, "apple", "banana", "cherry"}
}
|| Output a message indicating if "banana" is an
|| element of s.
The assertion that {italic banana} is in the set is ...
{s.member? "banana"}
|| Remove the element "banana" from s.
{s.remove "banana"}
|| Output a message indicating if "banana" is an
|| element is s.
After removing the element, the assertion is...
{s.member? "banana"}
|
クラス インスタンスが書き込まれるときに、シリアル化コードで呼び出されます。
説明
注意事項
要素を削除します。
説明
例
| 例: セットの要素を削除するために remove を使用する | |
{value
|| Declare and initialize my-set (a set).
let my-set:{Set-of String} =
{new {Set-of String}, "apple", "banana", "cherry"}
|| Remove an element
{my-set.remove "banana"}
|| Use a VBox to display the contents of my-set.
|| Iterate over the contents of my-set, adding them
|| to the VBox. Then display the VBox.
let message:VBox = {VBox}
{for each-element:String in my-set do
{message.add each-element}
}
message
}
|
要素が 1 つ削除された、セットのクローンを返します。
戻り値
説明
例
| 例: remove-clone を使用して[セット-1要素]をクローンする | |
{value
|| Declare and initialize set-1 (a 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, removing the "banana" element.
let set-2:{Set-of String} = {set-1.remove-clone "banana"}
|| 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
|| Create a new set.
let my-set:{Set-of String} =
{new {Set-of String}, "apple", "banana", "cherry"}
|| Create an Iterator-of from the set.
let my-iterator:{Iterator-of String} = {my-set.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
}
|
注意事項
注意事項
2 つ以上のセットの結合を形成します。
説明
例
| 例: 2 つ以上のセットのOR値を union を使用して形成する | |
{value
|| Declare and initialize set-1 (a set).
let set-1:{Set-of String} =
{new {Set-of String}, "apple", "banana", "cherry"}
|| Declare and initialize set-2 (a set).
let set-2:{Set-of String} =
{new {Set-of String}, "apple", "plum", "peach"}
|| In set-1, form the union of the elements in
|| set-1 and set-2.
{set-1.union set-2}
|| Use a VBox to display the contents of set-1.
|| Iterate over the contents of set-1, adding them
|| to the VBox. Then display the VBox.
let message:VBox = {VBox}
{for each-element:String in set-1 do
{message.add each-element}
}
message
}
|
2 つ以上のセットの結合を含むクローンを返します。
戻り値
説明
例
| 例: union-clone: N 個のセットの結合のクローンを形成する | |
{value
|| Declare and initialize set-1 (a set).
let set-1:{Set-of String} =
{new {Set-of String}, "apple", "banana", "cherry"}
|| Declare and initialize set-2 (a set).
let set-2:{Set-of String} =
{new {Set-of String}, "apple", "plum", "peach"}
|| Initialize set-3 with a clone of the contents
|| of set-1 unioned with the elements of set-2.
let set-3:{Set-of String} = {set-1.union-clone set-2}
|| Use a VBox to display the contents of set-3.
|| Iterate over the contents of set-3, adding them
|| to the VBox. Then display the VBox.
let message:VBox = {VBox}
{for each-element:String in set-3 do
{message.add each-element}
}
message
}
|
注意事項