6.34. kink/container/ORDER_SET¶
6.34.1. type order_set¶
`order_set` is a subtype of `set` type in which the elements are ordered in the toal order. The equivalence relation of elements is derived from the total order relation.
Total order relation of elements
The total order relation of elements, `up-to`, must suffice the following conditions for all X, Y, and Z in the domain of elements.
• reflexive: X up-to X
• transitive: if X up-to Y && Y up-to Z then X up-to Z
• antisymmetric: if X up-to Y && Y up-to X then X equivalent-to Y
• strongly connected: X up-to Y || Y up-to X
The antisymmetry condition is the definition of `equivalent-to`, which is the equivalence relation of elements.
Methods
`order_set` values have all the methods of `set`. The following methods inherited from `set` guarantee that elements appear as they are ordered by `up-to`.
• each
• all?
• any?
• count
• fold
• reduce
• have_all?
• have_any?
Additionally, `order_set` values have the following methods.
6.34.1.1. Set.order¶
`order` returns the function of the total order relation of elements of `Set`.
The result function, $up_to?, is a function which takes two args `X` and `Y`. `up_to?(X Y)` returns the bool value of `X up-to Y`, where `up-to` is the total order relation of elements.
6.34.1.2. Set.iter(...[Min])¶
`iter` method returns an `iter` of elements of `Set` in the order of `Set`.
If `Min` is given, the result `iter` will have elements bigger than or equivalent to `Min`. If `Min` is not given, the result `iter` will have all the elements of `Set`.
This method is an extension of `iter` method of type `set`.
Precondition
`Min` must be in the domain of the total order of elements.
Example
:TREE_SET.require_from('kink/container/')
:Set <- TREE_SET.of('foo' 'bar' 'baz' 'qux')
Set.iter.each{(:E) stdout.print_line(E.repr) }
# Output:
# "bar"
# "baz"
# "foo"
# "qux"
Set.iter('baz').each{(:E) stdout.print_line(E.repr) }
# Output:
# "baz"
# "foo"
# "qux"
Set.iter('bazzz').each{(:E) stdout.print_line(E.repr) }
# Output:
# "foo"
# "qux"
Set.iter('foo').each{(:E) stdout.print_line(E.repr) }
# Output:
# "foo"
# "qux"
Set.iter('foooo').each{(:E) stdout.print_line(E.repr) }
# Output:
# "qux"
6.34.1.3. Set.front¶
`front` returns the element which comes first in the order of `Set`.
Precondition
`Set` must not be empty.
Example
:TREE_SET.require_from('kink/container/')
:Set <- TREE_SET.of('foo' 'bar' 'baz')
stdout.print_line(Set.front.repr) # => "bar"
6.34.1.4. Set.back¶
`back` returns the element which comes last in the order of `Set`.
Precondition
`Set` must not be empty.
Example
:TREE_SET.require_from('kink/container/')
:Set <- TREE_SET.of('foo' 'bar' 'baz')
stdout.print_line(Set.back.repr) # => "foo"
6.34.1.5. Set.pop_front¶
`pop_front` pops the element which comes first in the order of `Set`.
Precondition
`Set` must not be empty.
Example
:FLAT_SET.require_from('kink/container/')
:Set <- FLAT_SET.of('foo' 'bar' 'baz')
:Front <- Set.pop_front
stdout.print_line(Front.repr) # => "bar"
stdout.print_line(Set.repr) # => Flat_set("baz" "foo")
6.34.1.6. Set.pop_back¶
`pop_back` pops the element which comes last in the order of `Set`.
Precondition
`Set` must not be empty.
Example
:FLAT_SET.require_from('kink/container/')
:Set <- FLAT_SET.of('foo' 'bar' 'baz')
:Back <- Set.pop_back
stdout.print_line(Back.repr) # => "foo"
stdout.print_line(Set.repr) # => Flat_set("bar" "baz")
6.34.2. ORDER_SET.is?(Val)¶
`is?` returns whether `Val` is an `order_set`.
6.34.3. ORDER_SET.mixin¶
`mixin` returns a mixin trait which provides default implementations of the following `order_set` methods.
• eq
• each
• all?
• any?
• count
• fold
• reduce
• have_all?
• have_any?
• append
• op_eq / `==` operator