6.33. kink/container/ORDERED_MAP¶
6.33.1. type ordered_map¶
`ordered_map` is a subtype of `map` type which supports total ordering of keys. Equivalence relation of keys is derived from the toal order.
6.33.1.1. Map.key_iter(...[Min_key])¶
`key_iter` returns an `iter` of keys following the order. If `Min_key` is passed, the iter will have the keys which are bigger than or equivalent to `Min_key`. If `Min_key` is not passed, the iter will have all the keys of `Map`.
`key_iter` method of `ordered_map` type extends the contract of `key_iter` of `map` type.
Precondition
`Min_key` must be in the domain of the total order of keys.
Example
:TREE_MAP.require_from('kink/container/')
:Map <- TREE_MAP.of(
'foo' 'FOO'
'bar' 'BAR'
'baz' 'BAZ'
'qux' 'QUX'
'grault' 'GRAULT'
)
Map.key_iter.each{(:K)
stdout.print_line(K.repr)
}
# Output:
# "bar"
# "baz"
# "foo"
# "grault"
# "qux"
Map.key_iter('f').each{(:K)
stdout.print_line(K.repr)
}
# Output:
# "foo"
# "grault"
# "qux"
6.33.1.2. Map.pair_iter(...[Min_key])¶
`pair_iter` returns an `iter` of pairs [Key Val] following the order. If `Min_key` is passed, the iter will have pairs whose keys are bigger than or equivalent to `Min_key`. If `Min_key` is not passed, the iter will have all the key-value pairs of `Map`.
`pair_iter` method of `ordered_map` type extends the constraints of `pair_iter` of `map` type.
Precondition
`Min_key` must be in the domain of the total order of keys.
Example
:TREE_MAP.require_from('kink/container/')
:Map <- TREE_MAP.of(
'foo' 'FOO'
'bar' 'BAR'
'baz' 'BAZ'
'qux' 'QUX'
'grault' 'GRAULT'
)
Map.pair_iter.each{(:Pair)
stdout.print_line(Pair.repr)
}
# Output:
# ["bar" "BAR"]
# ["baz" "BAZ"]
# ["foo" "FOO"]
# ["grault" "GRAULT"]
# ["qux" "QUX"]
Map.pair_iter('f').each{(:Pair)
stdout.print_line(Pair.repr)
}
# Output:
# ["foo" "FOO"]
# ["grault" "GRAULT"]
# ["qux" "QUX"]
6.33.1.3. Map.front_key¶
`front_key` returns the key which comes first in the order.
Precondition
`Map` must not be empty.
Example
:TREE_MAP.require_from('kink/container/')
:Map <- TREE_MAP.of(
'foo' 'FOO'
'bar' 'BAR'
'baz' 'BAZ'
'qux' 'QUX'
'grault' 'GRAULT'
)
stdout.print_line(Map.front_key.repr) # => "bar"
6.33.1.4. Map.back_key¶
`back_key` returns the key which comes last in the order.
Precondition
`Map` must not be empty.
Example
:TREE_MAP.require_from('kink/container/')
:Map <- TREE_MAP.of(
'foo' 'FOO'
'bar' 'BAR'
'baz' 'BAZ'
'qux' 'QUX'
'grault' 'GRAULT'
)
stdout.print_line(Map.back_key.repr) # => "qux"
6.33.2. ORDERED_MAP.is?(Val)¶
`is?` returns whether `Val` is an `ordered_map`.