{Dictionary-of K:Type, V:Type} (クラス)
public abstract Dictionary-of {inherits {Association-of K, V}}
パッケージ: CURL.IDE.CPA.BASE
直接継承しているサブクラス: HashDictionary-of

An ordered, potentially non-unique association of key and value.

説明

This class extends the Association-of interface to allow for multiple values for each key value and which orders the elements according to the ordered defined by the key-compare method.

Good implementations should provide O(log n) performance for lookup, insertion and deletion, and O(n) traversal.

プログラミング注意事項

Because there may be multiple values per key, you should avoid iterating over the keys and values of the dictionary using the form:

{for v key k in dictionary do ...}


which will only visit one value per key using get. Instead you should use the enumeration method to get an iterator that will visit all of the key/value pairs:

{for (k, v) in {dictionary.enumeration} do ...}

プロパティ
naturally-ordered?:Indicates whether data in dictionary is naturally ordered by key.
アクセサ public abstract Dictionary-of.naturally-ordered?:bool
プロパティ 継承 Association-of: efficient-size, empty?, key-type, size
プロパティ 継承 Aggregate-of: element-type

メソッド
clear:すべての要素を削除します。
public abstract {Dictionary-of.clear}:void
clone:コレクションのクローンを返します。
public abstract {Dictionary-of.clone}:{this-class}
contains-key-value?:Does dictionary contain value associated with given key?
public {Dictionary-of.contains-key-value? k:K, v:V}:bool
enumeration:Produces a general iterator for the contents of the dictionary.
public abstract {Dictionary-of.enumeration
direction:SearchDirection = SearchDirection.forward,
from:K = {uninitialized-value-for-type K}
}:{DictionaryIterator-of K, V}
filter:フィルタ操作内で要素を使って要素自体をフィルタリングします。
public abstract {Dictionary-of.filter keep?:{proc-type {V}:bool}}:void
filter-clone:(フィルタ操作内で要素を使って) クローンの要素が選別された、コレクションのクローンを返します。
public {Dictionary-of.filter-clone p:{proc-type {V}:bool}}:{this-class}
filter-keys:フィルタ操作でキーを使って要素をフィルタリングします。
public abstract {Dictionary-of.filter-keys
keep?:{proc-type {K}:bool}
}:void
filter-keys-clone:(フィルタ操作内でキーを使って) 要素が選別された、コレクションのクローンを返します。
public {Dictionary-of.filter-keys-clone
p:{proc-type {K}:bool}
}:{this-class}
for-each:Apply function to key/value pairs in dictionary in order.
public {Dictionary-of.for-each
continue?:{proc-type {K,V}:bool},
from:K = {uninitialized-value-for-type K},
direction:SearchDirection = SearchDirection.forward,
in-order?:bool = self.naturally-ordered?
}:int
for-each-with-key:Apply function to key/value pairs for given key.
public {Dictionary-of.for-each-with-key
key:K,
continue?:{proc-type {K, V}:bool},
direction:SearchDirection = SearchDirection.forward
}:int
insert-key-value:Inserts a new key and value association into the dictionary.
public abstract {Dictionary-of.insert-key-value k:K, v:V}:void
key-compare:Compares two keys.
public {Dictionary-of.key-compare k1:K, k2:K}:int
keys-to-Iterator:Produce an iterator over values in the dictionary.
public {Dictionary-of.keys-to-Iterator}:{Iterator-of K}
remove-key-value:Removes a key and value association from the dictionary.
public abstract {Dictionary-of.remove-key-value
k:K,
v:V,
remove-all?:bool = false
}:int
replace-key-value:Associates a key with a new value.
public abstract {Dictionary-of.replace-key-value
k:K,
old-v:V,
new-v:V
}:bool
reverse-enumeration:Produces a general reverse iterator for the contents of the dictionary.
public {Dictionary-of.reverse-enumeration
from:K = {uninitialized-value-for-type K}
}:{DictionaryIterator-of K, V}
set:Associates given key and value in dictionary.
public {Dictionary-of.set k:K, v:V}:void
to-Iterator:Produce an iterator over keys in the dictionary.
public {Dictionary-of.to-Iterator}:{Iterator-of V}
メソッド 継承 Association-of: get, get-if-exists, get-key, get-key-if-exists, key-exists?, remove
メソッド 継承 Object: object-describe, object-describe-for-debugging, object-serialize




プロパティ詳細
naturally-ordered? (アクセサ)
アクセサ public abstract Dictionary-of.naturally-ordered?:bool

Indicates whether data in dictionary is naturally ordered by key.

説明

When true to-Iterator and keys-to-Iterator should return values in order of increasing key value according to the key-compare method, and the enumeration method is expected to cost O(n) to iterate over all of the elements. This is also the default value of the in-order? keyword to the for-each method.





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

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

説明

このメソッドは、コレクションを反復処理することで、一度に 1 つの要素を削除します。Association-ofをサブクラス化すると、このメソッドをオーバーライドし、効率的な実装が可能になります。たとえば、コレクションに書き込み可能な size プロパティがある場合、要素を反復処理するよりも size をリセットする方が効率的です。


{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 abstract {Dictionary-of.clone}:{this-class}

コレクションのクローンを返します。

戻り値

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

説明

クローンは、self と同じデータ型を持つ新しいオブジェクトです。クローンには、self の要素の簡易コピー(shallow copy) が含まれます。つまり、どちらかのコレクションの要素に新しいオブジェクトを代入すると、もう一方の一致した要素は元のオブジェクトを参照します。ただし、要素のオブジェクトを変更すると、両方のコレクションは変更したオブジェクトを参照します。


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

注意事項

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

注意事項

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


contains-key-value? (メソッド)
public {Dictionary-of.contains-key-value? k:K, v:V}:bool

Does dictionary contain value associated with given key?

説明

This method indicates whether it contains the given value v associated with the key k.


enumeration (メソッド)
public abstract {Dictionary-of.enumeration
direction:SearchDirection = SearchDirection.forward,
from:K = {uninitialized-value-for-type K}
}:{DictionaryIterator-of K, V}

Produces a general iterator for the contents of the dictionary.

direction: specifies whether to initially iterate forward or backward in the dictionary.
from: specifies the starting point for iteration. If specified, iteration will start from the first entry with the given key if iterating forward and the last entry with the given key if iterating backward. If there is no instance of the given key in the dictionary, iteration will start at the point at which such a key would be inserted. If not specified, the starting point will be the first entry with the lowest key if iterating forward and the last entry with the highest key if iterating backward.

説明

This produces an iterator for the dictionary with a given direction and starting point. By default it iterates forward through the entire collection. The iterator iterates over the key and value in parallel and typically is used like this:

{for (key, value) in {dictionary.enumeration} do
    ...
}


Also see reverse-enumeration.

See DictionaryIterator-of for more details about the iterator.


filter (メソッド)
public abstract {Dictionary-of.filter keep?:{proc-type {V}:bool}}:void

フィルタ操作内で要素を使って要素自体をフィルタリングします。

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

戻り値

このメソッドは値を返しません。

説明

p への呼び出しが false を返すコレクションの要素を削除します。

次の例では、ハッシュ テーブルから要素をフィルタリングします。


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


filter-clone (メソッド)
public {Dictionary-of.filter-clone p:{proc-type {V}:bool}}:{this-class}

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

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 (メソッド)
public abstract {Dictionary-of.filter-keys
keep?:{proc-type {K}:bool}
}:void

フィルタ操作でキーを使って要素をフィルタリングします。

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

説明

関連付けられたキーを持つ p への呼び出しが false を返す self の要素を削除します。


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


filter-keys-clone (メソッド)
public {Dictionary-of.filter-keys-clone
p:{proc-type {K}:bool}
}:{this-class}

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

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 開発者ガイド』の「コレクション」で、使用しているコレクションのクローンに関するセクションを参照してください。


for-each (メソッド)
public {Dictionary-of.for-each
continue?:{proc-type {K,V}:bool},
from:K = {uninitialized-value-for-type K},
direction:SearchDirection = SearchDirection.forward,
in-order?:bool = self.naturally-ordered?
}:int

Apply function to key/value pairs in dictionary in order.

説明

Invokes continue? on each key/value pair in the dictionary starting with from and proceeding forward or backward according to direction until hitting either end of the dictionary or until continue? returns false.

If in-order? is false, then the pairs may not be visited in order of increasing key. It only makes sense to use this argument for subclasses for which naturally-ordered? is false.

Returns the number of times that continue? was invoked.

The default implementation iterates of the dictionary using enumeration with the given parameters.


for-each-with-key (メソッド)
public {Dictionary-of.for-each-with-key
key:K,
continue?:{proc-type {K, V}:bool},
direction:SearchDirection = SearchDirection.forward
}:int

Apply function to key/value pairs for given key.

説明

Invokes continue? for each key/value pair in the dictionary whose key matches given key until continue? returns false.

Returns the number of times that continue? was invoked.

The default implementation calls for-each.


insert-key-value (メソッド)
public abstract {Dictionary-of.insert-key-value k:K, v:V}:void

Inserts a new key and value association into the dictionary.

説明

Inserts a new association between key k and value v into the dictionary. Multiple values may be inserted for the same key, and the order of such values with respect to each other is arbitrary. Specific subclasses may provide a defined ordering for such cases.


key-compare (メソッド)
public {Dictionary-of.key-compare k1:K, k2:K}:int

Compares two keys.

説明

Returns a number less than, equal to, or greater than zero, corresponding to when k1 is less than, equal to, or greater than k2. Thus this defines both the order and equality relation ship between keys in the dictionary.

The default implemention simply uses the compare syntax.


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

Produce an iterator over values in the dictionary.

説明

Produces an iterator that will return each value in the dictionary in order according to it's associated key and the key-compare method.

The enumeration method provides a more powerful iteration technique.


remove-key-value (メソッド)
public abstract {Dictionary-of.remove-key-value
k:K,
v:V,
remove-all?:bool = false
}:int

Removes a key and value association from the dictionary.

説明

Removes at least one association between k and v from the dictionary. If remove-all? is true then all associations between k and v will be removed, otherwise only one will be removed and others may still remain.

Returns the number of associations removed. Will return zero if there is no such association.


replace-key-value (メソッド)
public abstract {Dictionary-of.replace-key-value
k:K,
old-v:V,
new-v:V
}:bool

Associates a key with a new value.

説明

Replaces an existing association between key k and value old-v with one between k and new-v. If there was no existing association between k and old-v, this is equivalent to invoking insert-key-value with k and v.

If there are already multiple associations between k and old-v when this was invoked, then this will replace an arbitrary one of them.

Returns true if old-v was replaced by v, and returns false if a new association was simply inserted.


reverse-enumeration (メソッド)
public {Dictionary-of.reverse-enumeration
from:K = {uninitialized-value-for-type K}
}:{DictionaryIterator-of K, V}

Produces a general reverse iterator for the contents of the dictionary.

説明

This is equivalent to invoking enumeration with direction set to SearchDirection.backward.


set (メソッド)
public {Dictionary-of.set k:K, v:V}:void

Associates given key and value in dictionary.

説明

If there is already a value associated with k then this will replace the value with v using replace-key-value, otherwise it will insert the key and value using insert-key-value.

If there are already multiple values associated with k when this was invoked, then this will replace an arbitrary one of them, so typically this method should only be used when you do not intend to store multiple values for the same key.


to-Iterator (メソッド)
public {Dictionary-of.to-Iterator}:{Iterator-of V}

Produce an iterator over keys in the dictionary.

説明

Produces an iterator that will return each key in the dictionary in order according to the key-compare method.

The enumeration method provides a more powerful iteration technique.