{HashTable-of tk:Type, te:Type, key-hash-proc:any = value-hash, key-equality-proc:any = equal? } (クラス)
public serializable HashTable-of {inherits {Association-of tk, te}}
パッケージ: CURL.LANGUAGE.CONTAINERS
直接継承しているサブクラス: JsonObject, HttpHeaders

ハッシュ テーブルのパラメータ化クラス。

tk: ハッシュ テーブル内のキーのデータ型。
te: ハッシュ テーブル内の要素のデータ型。
key-hash-proc: キーのハッシュ値を返すプロシージャ。このプロシージャには、ハッシュ テーブルのキーと同じデータ型 (tk) を持つ 1 つのパラメータを指定できます。このプロシージャは int を返します。key-hash-prockey-equality-proc には、相互に一貫性のある意味を持たせる必要があります。2 つのキーに対する key-equality-proc への呼び出しが true を返す場合、2 つのキーそれぞれに対する key-hash-proc への呼び出しで、同じハッシュ値が生成される必要があります。key-hash-proc の既定値は value-hash です。
key-equality-proc: 2 つのキーが等しいかどうかを判定するプロシージャ。このプロシージャにはハッシュ テーブルのキーと同じデータ型 (tk) を持つ 2 つのパラメータを指定できます。このプロシージャは bool を返します。2 つのキーが等しい場合、このプロシージャは true を返します。それ以外の場合、false を返します。key-hash-prockey-equality-proc には、相互に一貫性のある意味を持たせる必要があります。2 つのキーに対する key-equality-proc への呼び出しがtrue を返す場合、2 つのキーそれぞれに対する key-hash-proc への呼び出しは、同じハッシュ値を生成する必要があります。key-equality-proc の既定値は equal? です。

説明

Curl言語には、以下のようなコレクション タイプが組み込まれています。



ハッシュ テーブルは、要素の順序付けられていないコレクションです。各要素には関連付けられたキーがあります。そのキーを使用して要素にアクセスします。キーと要素には、データ型を指定できます。たとえば、String キーを指定できます。

注意事項

Curl のコレクションクラスの部分階層は次のようになります。
Curl のコレクションの詳細は、Curl 開発者ガイド: コレクション を参照してください。

注意事項

同じキー値を持つ複数のエントリを含めた場合、最後のエントリはハッシュ テーブルに格納されます。

注意事項

コレクションを反復処理中にコレクションの内容を変更することは出来ません。

コンストラクタ
clone-from:HashTable-of を初期化します。
コンストラクタ public {HashTable-of.clone-from
from:{HashTable-of tk, te, key-hash-proc = key-hash-proc, key-equality-proc = key-equality-proc }
}
default:HashTable-of を初期化します。
コンストラクタ public {HashTable-of.default efficient-size:int = 4, ...:any}
object-deserialize:
コンストラクタ public {HashTable-of.object-deserialize in:SerializeInputStream}

プロパティ
efficient-size:selfefficient-size を取得または設定します。
アクセサ public HashTable-of.efficient-size:int
セッター public HashTable-of.efficient-size:int
size:コレクションの要素数を返します。
アクセサ public HashTable-of.size:int
プロパティ 継承 Association-of: empty?, key-type
プロパティ 継承 Aggregate-of: element-type

メソッド
clear:すべての要素を削除します。
public {HashTable-of.clear}:void
clone:ハッシュ テーブルのクローンを返します。
public {HashTable-of.clone
}:{HashTable-of tk, te, key-hash-proc=key-hash-proc, key-equality-proc=key-equality-proc }
filter-clone:(フィルタ操作内で要素を使って) クローンの要素が選別された、コレクションのクローンを返します。
public {HashTable-of.filter-clone
p:{proc-type {te}:bool}
}:{HashTable-of tk, te}
filter-keys-clone:(フィルタ操作内でキーを使って) 要素が選別された、コレクションのクローンを返します。
public {HashTable-of.filter-keys-clone
p:{proc-type {tk}:bool}
}:{HashTable-of tk, te}
get-if-exists:key でインデックス付けされた要素と、示された要素が見つかったかどうかを示すブール値を返します。
public {HashTable-of.get-if-exists key:tk}:(value:te, found?:bool)
get-key-if-exists:特定のキーと、示された要素が見つかったかどうかを示すブール値を返します。
public {HashTable-of.get-key-if-exists key:tk}:(key:tk, found?:bool)
grow:ハッシュ テーブルを内部的に表す構造を大きくします。
public {HashTable-of.grow}:void
key-exists?:キーが存在するかどうかを調べます。
public {HashTable-of.key-exists? key:tk}:bool
keys-to-Iterator:コレクションの各キーを含む Iterator-of を返します。
public {HashTable-of.keys-to-Iterator}:{Iterator-of tk}
object-serialize:クラス インスタンスが書き込まれるときに、シリアル化コードで呼び出されます。
public {HashTable-of.object-serialize out:SerializeOutputStream}:void
rehash:self を再ハッシュします。
public {HashTable-of.rehash}:void
remove:要素を削除します。
public {HashTable-of.remove
key:tk,
length:int = 1,
error-if-missing?:bool = true
}:void
set:要素の値を設定します。
public {HashTable-of.set key:tk, element:te}:void
to-Iterator:self の要素を生成する Iterator-of を返します。
public {HashTable-of.to-Iterator}:{Iterator-of te}
メソッド 継承 Association-of: filter, filter-keys, get, get-key
メソッド 継承 Object: object-describe, object-describe-for-debugging



コンストラクタ詳細
clone-from (コンストラクタ)
public {HashTable-of.clone-from
from:{HashTable-of tk, te, key-hash-proc = key-hash-proc, key-equality-proc = key-equality-proc }
}

HashTable-of を初期化します。

from: self の初期の内容は from からコピーされます。


default (コンストラクタ)
public {HashTable-of.default efficient-size:int = 4, ...:any}

HashTable-of を初期化します。

efficient-size: 効率を高めるためにハッシュ テーブルを調整するのに使用する、ハッシュ テーブルの推定サイズ。指定した値以上の値が適切な値として選択されるので注意してください。この値は、efficient-size ゲッターによって取得される場合もあります。
...: 残余引数は、ハッシュ テーブルに最初に設定するキーと要素を指定します。キーと要素をペアで (キー、要素の順に) 指定します。キーと要素は、カンマで区切ります。

説明

新しい HashTable-of オブジェクトを初期化します。残余引数が提供される場合、残余引数をハッシュ テーブルの初期値として含めます。


object-deserialize (コンストラクタ)
public {HashTable-of.object-deserialize in:SerializeInputStream}
この項目はサポートされていません。内部使用限定となっています。



プロパティ詳細
efficient-size (アクセサ)
アクセサ public HashTable-of.efficient-size:int
セッター public HashTable-of.efficient-size:int

selfefficient-size を取得または設定します。

説明

これは Association-of.efficient-size で定義された有効なサイズを実装したものです。


size (アクセサ)
アクセサ public HashTable-of.size:int

コレクションの要素数を返します。

戻り値

self の要素数を示すint


{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.}
}

注意事項

これは Association-of の抽象メソッドで、Association-of のサブクラス内で実装されます。





メソッド詳細
clear (メソッド)
public {HashTable-of.clear}:void

すべての要素を削除します。


{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?}}
}


clone (メソッド)
public {HashTable-of.clone
}:{HashTable-of tk, te, key-hash-proc=key-hash-proc, key-equality-proc=key-equality-proc }

ハッシュ テーブルのクローンを返します。

戻り値

HashTable-of のインスタンス。オブジェクトは、self と同じデータ型およびデータを持ちます。

説明

クローンは、self と同じデータ型を持つ新しいオブジェクトです。クローンは、self の浅いコピー(shallow copy)です。つまり、クローンには self の元の要素への固有の参照が含まれます。したがって、元のコレクション内の要素を置換または削除しても、クローン コレクション内の要素には影響しません。


|| 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}

注意事項

クローンの詳細については、『Curl 開発者ガイド』の「コレクション:ハッシュ テーブル」でクローンに関するセクションを参照してください。


filter-clone (メソッド)
public {HashTable-of.filter-clone
p:{proc-type {te}:bool}
}:{HashTable-of tk, te}

(フィルタ操作内で要素を使って) クローンの要素が選別された、コレクションのクローンを返します。

p: 要素をフィルタリングするプロシージャ。このメソッドは、self の各要素に対して p を呼び出します。プロシージャには、self の要素と同じデータ型を持つ 1 つの引数を指定する必要があります。プロシージャは、このメソッドが要素をフィルタリングするかどうかを示す bool 値を返す必要があります。pfalse を返す場合、このメソッドは self からその要素をフィルタリング (削除) します。ptrue を返す場合、要素は、self 内に残ります。

戻り値

Association-of のサブクラスのインスタンス。オブジェクトは、self と同じデータ型を持ちます。オブジェクトには、いくつかの要素がフィルタリングされた、コレクションのクローンが含まれます。

説明

このメソッドは、self のクローンを返します。クローンでは、p プロシージャへの呼び出しが false を返す要素が削除されます。クローンとは、self と同じデータ型を持つ新しいオブジェクトです。クローンには、self の浅い要素のコピー(shallow copy) が含まれます。つまり、どちらかの集合の要素に新しいオブジェクトを代入すると、もう一方の一致した要素は元のオブジェクトを参照します。ただし、要素のオブジェクトを変更すると、両方の集合は変更したオブジェクトを参照します。

次の例は、先頭に文字 d が付くすべての要素が除外されたハッシュ テーブルのクローンを作成します。


{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.
}

注意事項

クローンの詳細については、『Curl 開発者ガイド』の「コレクション」で、使用しているコレクションのクローンに関するセクションを参照してください。


filter-keys-clone (メソッド)
public {HashTable-of.filter-keys-clone
p:{proc-type {tk}:bool}
}:{HashTable-of tk, te}

(フィルタ操作内でキーを使って) 要素が選別された、コレクションのクローンを返します。

p: 要素をフィルタリングするプロシージャ。このメソッドは、self の各キーに対して p を呼び出します。プロシージャには、self のキーと同じデータ型を持つ 1 つの引数を指定する必要があります。プロシージャは、関連付けられた要素をこのメソッドがフィルタリングするかどうかを示す bool 値を返す必要があります。pfalse を返す場合、このメソッドは self からその要素をフィルタリング (削除) します。ptrue を返す場合、要素は、self 内に残ります。

戻り値

Association-of のサブクラスのインスタンス。オブジェクトは、self と同じデータ型を持ちます。

説明

このメソッドは、self のクローンを返します。クローンでは、関連付けられたキーを持つ p への呼び出しが false を返す self の要素が削除されます。クローンとは、self と同じデータ型を持つ新しいオブジェクトです。クローンには、self の浅い要素のコピー(shallow copy)が含まれます。つまり、どちらかの集合の要素に新しいオブジェクトを代入すると、もう一方の一致した要素は元のオブジェクトを参照します。ただし、要素のオブジェクトを変更すると、両方の集合は変更したオブジェクトを参照します。


{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.
}

注意事項

クローンの詳細については、『Curl 開発者ガイド』の「コレクション」で、使用しているコレクションのクローンに関するセクションを参照してください。


get-if-exists (メソッド)
public {HashTable-of.get-if-exists key:tk}:(value:te, found?:bool)

key でインデックス付けされた要素と、示された要素が見つかったかどうかを示すブール値を返します。

key: 取得する要素のキーの値。

戻り値

このメソッドは次の 2 つの値を返します。2 番目に返される値が false の場合、最初に返される値は不確定です。


get-key-if-exists (メソッド)
public {HashTable-of.get-key-if-exists key:tk}:(key:tk, found?:bool)

特定のキーと、示された要素が見つかったかどうかを示すブール値を返します。

key: 取得するキーの値。

戻り値

指定されたキーに等しいコンテナが使用しているキー。戻り値は、self のキーと同じデータ型を持ちます。また、キーが見つかったかどうかを示すフラグを返します。

説明

key パラメータが self 内のキーの場合、そのキーを返します。この場合、2 番目に返される値は true になります。それ以外の場合、返される値は定義されず、2 番目に戻される値は false になります。


|| 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"}

注意事項

このメソッドは、Association-ofで実装されます。Association-of のいくつかのサブクラス内でオーバーライドされます。


grow (メソッド)
public {HashTable-of.grow}:void

ハッシュ テーブルを内部的に表す構造を大きくします。

説明

内部テーブルのサイズを 2 の次の累乗に増やします。self を新しいテーブルに再ハッシュします。


key-exists? (メソッド)
public {HashTable-of.key-exists? key:tk}:bool

キーが存在するかどうかを調べます。

key: 調べるキーの値。値は、self のキーと同じデータ型を持つ必要があります。

戻り値

bool 値。値が self のキーである場合、このメソッドは true を返します。それ以外の場合は、false を返します。


{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.}
    }
}


keys-to-Iterator (メソッド)
public {HashTable-of.keys-to-Iterator}:{Iterator-of tk}

コレクションの各キーを含む Iterator-of を返します。

戻り値

self の要素と同じパラメータ化データ型を持つ Iterator-of。つまり、self{Association-of int, String} の場合、このメソッドは {Iterator-of int} を返します。

説明

Iterator-of のキーの順序は、任意に指定できます (Association-of のインスタンスが、順序付けられたコレクションでない場合もあるからです)。


{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.
}

注意事項

for コンテナ ループを使って同じ結果を得ることもできます。ただし、この反復処理メカニズムをオーバーライドすると、予期外の結果が生じる可能性があるので、可能な限り for ループを使用してください。

注意事項

これは Association-of の抽象メソッドで、Association-of のサブクラス内で実装されます。


object-serialize (メソッド)
public {HashTable-of.object-serialize out:SerializeOutputStream}:void

クラス インスタンスが書き込まれるときに、シリアル化コードで呼び出されます。

out: このメソッドを呼び出した SerializeOutputStream

説明

このメソッドは、次のステップを順番に実行する必要があります。
  1. SerializeOutputStream.write-class-version を呼び出します。通常は引数にゼロ (0) を指定します。
  2. シリアル化可能なスーパークラスごとに super.object-serialize を呼び出します。
  3. シリアル化された状態を out に書き込みます。これは通常、フィールドごとに SerializeOutputStream.write-one を呼び出すことによって実行されます。

注意事項

このメソッドは、シリアル化可能なサブクラスでのみ定義する必要があります。


rehash (メソッド)
public {HashTable-of.rehash}:void

self を再ハッシュします。



remove (メソッド)
public {HashTable-of.remove
key:tk,
length:int = 1,
error-if-missing?:bool = true
}:void

要素を削除します。

key: 削除する要素のキーの値。この値は、self のキーと同じデータ型を持つ必要があります。
length: このパラメータを指定するとエラーになります。

length コレクションから削除する連続する要素の数を示す int。ただし、このメソッドでは、ハッシュ テーブルは順序付けられたコレクションではないので、このパラメータには意味がありません。このパラメータは、順序付けられたコレクションを実装する Sequence-of のサブクラスにのみ適用されます。

このメソッドでは、length は既定値の 1 に設定されています。
error-if-missing?: ユーザーが存在しない要素を削除しようとしたときにこのメソッドがエラーを生成するかどうかを示すブール値のフラグ。error-if-missing?true に設定した場合、存在しない要素を削除しようとするとエラーがスローされます。エラーが発生するとプログラムの実行が停止し、エラー メッセージが表示されます。既定では、error-if-missing?true です。error-if-missing?false の場合、このメソッドはエラーを生成しません。error-if-missing? キーワード引数。error-if-missing?を指定するには、メソッド呼び出し内のキーワードに必要な値 (例:error-if-missing?=false) を指定します。

説明

{self.key-exists? key}true を返す場合、このメソッドは self から適切なキーおよび要素を削除します。

{self.key-exists? key}false で、 error-if-missing?true の場合、このメソッドはエラーをスローします。ただし、 error-if-missing?false の場合、このメソッドは何のアクションも実行しません。


{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.
}

注意事項

これは Association-of の抽象メソッドで、Association-of のサブクラス内で実装されます。


set (メソッド)
public {HashTable-of.set key:tk, element:te}:void

要素の値を設定します。

key: 設定する要素のキーの値。この値は、self のキーと同じデータ型を持つ必要があります。
element: 要素の値。この値は、selfの要素と同じデータ型を持つ必要があります。

説明

keyself に存在する場合、このメソッドは element に関連付けられた要素の値を変更します。keyself に存在しない場合、このメソッドは新しい要素 (keyelement) を self に追加します。


{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.
}

注意事項

これは Association-of の抽象メソッドで、Association-of のサブクラス内で実装されます。


to-Iterator (メソッド)
public {HashTable-of.to-Iterator}:{Iterator-of te}

self の要素を生成する Iterator-of を返します。

戻り値

self の要素と同じパラメータ化データ型を持つ Iterator-of。つまり、self{HashTable-of int, String } の場合、このメソッドは {{Iterator-of String}} を返します。


{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
}

注意事項

ハッシュ テーブルは、順序付けられていないコレクションなので、Iterator-of 内の要素の順序は任意に指定できます。

注意事項

forコンテナ ループを使用しても同じ結果を得ることができます。ただし、この反復処理メカニズムをオーバーライドすると、予想外の結果が生じる場合があるので、実際にはコンテナの反復には for を使用することをお勧めします。