6.34. kink/container/ORDERED_SET

6.34.1. type ordered_set

`ordered_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.

The following methods inherited from `set` guarantee that elements appear as they are ordered.

• each

• all?

• any?

• count

• fold

• reduce

• have_all?

• have_any?

6.34.1.1. 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.2. 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.3. 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.4. 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.5. 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. ORDERED_SET.is?(Val)

`is?` returns whether `Val` is an `ordered_set`.