indexing
description: "Trees implemented using a two way linked list representation"
status: "See notice at end of class"
names: two_way_tree, tree, two_way_list
representation: recursive, linked
access: cursor, membership
contents: generic
date: "$Date$"
revision: "$Revision$"
class interface
TWO_WAY_TREE [G]
create
make (v: like item)
v
feature
make (v: like item)
v
feature
child_cursor: CURSOR
LINKED_LIST
first: like child_item
LINKED_LIST
require CHAIN
not_empty: not is_leaf
first_child: like parent
i_th (i: INTEGER): like child_item
i
CHAIN@
CHAIN
require TABLE
valid_key: valid_index (k)
child_index: INTEGER
LINKED_LIST
ensure TREE
valid_index: Result >= 0 and Result <= arity + 1
index_of (v: like child_item; i: INTEGER): INTEGER
iv
object_comparison
CHAIN
require LINEAR
positive_occurrences: i > 0
ensure LINEAR
non_negative_result: Result >= 0
child_item: G
LINKED_LIST
require TRAVERSABLE
not_off: not child_off
require ACTIVE
readable: child_readable
require TREE
readable: child_readable
item: G
CELL
last: like child_item
LINKED_LIST
require CHAIN
not_empty: not is_leaf
last_child: like parent
left_sibling: like Current
BI_LINKABLE
sequential_occurrences (v: G): INTEGER
v
object_comparison
LINEAR
ensure BAG
non_negative_occurrences: Result >= 0
parent: TWO_WAY_TREE [G]
right_sibling: like Current
LINKABLE
sublist: like Current
split
TWO_WAY_LIST
infix "@" (i: INTEGER): like child_item
i
CHAINi_th
CHAIN
require TABLE
valid_key: valid_index (k)
feature
child_capacity: INTEGER
TREE
count: INTEGER
TREE
arity: INTEGER
LINKED_LIST
index_set: INTEGER_INTERVAL
CHAIN
ensure INDEXABLE
not_void: Result /= void
ensure then CHAIN
count_definition: Result.count = arity
occurrences (v: like child_item): INTEGER
v
object_comparison
CHAIN
ensure BAG
non_negative_occurrences: Result >= 0
occurrences (v: like child_item): INTEGER
v
object_comparison
CHAIN
ensure BAG
non_negative_occurrences: Result >= 0
feature
is_equal (other: like Current): BOOLEAN
other
object_comparison
TREE
require ANY
other_not_void: other /= void
ensure ANY
symmetric: Result implies other.is_equal (Current)
consistent: standard_is_equal (other) implies Result
ensure then LIST
indices_unchanged: child_index = old child_index and other.child_index = old other.child_index
true_implies_same_size: Result implies arity = other.arity
feature
child_after: BOOLEAN
LINKED_LIST
child_before: BOOLEAN
LINKED_LIST
changeable_comparison_criterion: BOOLEAN
object_comparison
CONTAINER
child_isfirst: BOOLEAN
TREE
ensure CHAIN
valid_position: Result implies not is_leaf
ensure TREE
not_is_leaf: Result implies not is_leaf
child_islast: BOOLEAN
TREE
ensure CHAIN
valid_position: Result implies not is_leaf
ensure TREE
not_is_leaf: Result implies not is_leaf
child_readable: BOOLEAN
child_item
TREE
child_writable: BOOLEAN
child_item
TREE
exhausted: BOOLEAN
LINEAR
ensure LINEAR
exhausted_when_off: child_off implies Result
Extendible: BOOLEAN is True
DYNAMIC_TREE
Child_extendible: BOOLEAN is True
DYNAMIC_CHAIN
has (v: G): BOOLEAN
v
object_comparison
TREE
ensure CONTAINER
not_found_in_empty: Result implies not is_leaf
is_empty: BOOLEAN
TREE
is_inserted (v: G): BOOLEAN
vput
extend
LINKED_LIST
is_leaf: BOOLEAN
TREE
is_root: BOOLEAN
TREE
is_sibling (other: like parent): BOOLEAN
other
TREE
require TREE
other_exists: other /= void
ensure TREE
not_root: Result implies not is_root
other_not_root: Result implies not other.is_root
same_parent: Result = not is_root and other.parent = parent
object_comparison: BOOLEAN
equal=
=
CONTAINER
child_off: BOOLEAN
LINKED_LIST
prunable: BOOLEAN
DYNAMIC_CHAIN
Readable: BOOLEAN is True
TREE
readable_child: BOOLEAN
TREE
valid_cursor (p: CURSOR): BOOLEAN
p
LINKED_LIST
valid_cursor_index (i: INTEGER): BOOLEAN
i
TREE
ensure CHAIN
valid_cursor_index_definition: Result = ((i >= 0) and (i <= arity + 1))
ensure TREE
valid_cursor_index_definition: Result = (i >= 0) and (i <= child_capacity + 1)
valid_index (i: INTEGER): BOOLEAN
i
CHAIN
ensure then INDEXABLE
only_if_in_index_set: Result implies ((i >= index_set.lower) and (i <= index_set.upper))
ensure then CHAIN
valid_index_definition: Result = ((i >= 1) and (i <= arity))
Writable: BOOLEAN is True
TREE
writable_child: BOOLEAN
TREE
feature
compare_objects
equal
=
CONTAINER
require CONTAINER
changeable_comparison_criterion
ensure CONTAINER
object_comparison
compare_references
=
equal
CONTAINER
require CONTAINER
changeable_comparison_criterion
ensure CONTAINER
reference_comparison: not object_comparison
feature
child_back
TWO_WAY_LIST
require TREE
True
require BILINEAR
not_before: not child_before
child_finish
TWO_WAY_LIST
ensure then CHAIN
at_last: not is_leaf implies child_islast
ensure then LINKED_LIST
empty_convention: is_leaf implies child_before
ensure then TREE
is_last_child: not is_leaf implies child_islast
ensure then TWO_WAY_LIST
not_after: not child_after
child_forth
TWO_WAY_LIST
require TREE
True
require LINEAR
not_after: not child_after
ensure then LIST
moved_forth: child_index = old child_index + 1
child_go_i_th (i: INTEGER)
i
LINKED_LIST
require CHAIN
valid_cursor_index: valid_cursor_index (i)
require else TREE
valid_cursor_index: valid_cursor_index (i)
ensure CHAIN
position_expected: child_index = i
ensure then TREE
position: child_index = i
child_go_to (p: CURSOR)
p
LINKED_LIST
require TREE
True
require CURSOR_STRUCTURE
cursor_position_valid: valid_cursor (p)
move (i: INTEGER)
i
off
TWO_WAY_LIST
ensure CHAIN
too_far_right: (old child_index + i > arity) implies exhausted
too_far_left: (old child_index + i < 1) implies exhausted
expected_index: (not exhausted) implies (child_index = old child_index + i)
ensure then LINKED_LIST
moved_if_inbounds: ((old child_index + i) >= 0 and (old child_index + i) <= (arity + 1)) implies child_index = (old child_index + i)
before_set: (old child_index + i) <= 0 implies child_before
after_set: (old child_index + i) >= (arity + 1) implies child_after
search_child (v: like child_item)
itemv
v
exhausted
object_comparison
BILINEAR
ensure LINEAR
object_found: (not exhausted and object_comparison) implies equal (v, child_item)
item_found: (not exhausted and not object_comparison) implies v = child_item
child_start
LINKED_LIST
ensure then CHAIN
at_first: not is_leaf implies child_isfirst
ensure then TREE
is_first_child: not is_leaf implies child_isfirst
ensure then LINKED_LIST
empty_convention: is_leaf implies child_after
feature
append (s: SEQUENCE [G])
s
SEQUENCE
require SEQUENCE
argument_not_void: s /= void
ensure SEQUENCE
new_count: arity >= old arity
extend (v: like item)
v
DYNAMIC_TREE
child_extend (v: like child_item)
v
TWO_WAY_LIST
require DYNAMIC_TREE
True
require COLLECTION
extendible: child_extendible
ensure COLLECTION
item_inserted: is_inserted (v)
ensure then BAG
one_more_occurrence: occurrences (v) = old (occurrences (v)) + 1
fill (other: TREE [G])
other
other
TREE
force (v: like child_item)
v
SEQUENCE
require SEQUENCE
extendible: child_extendible
ensure then SEQUENCE
new_count: arity = old arity + 1
item_inserted: has (v)
twl_merge_left (other: like Current)
other
other
TWO_WAY_LIST
require DYNAMIC_CHAIN
extendible: child_extendible
not_before: not child_before
other_exists: other /= void
ensure DYNAMIC_CHAIN
new_count: arity = old arity + old other.arity
new_index: child_index = old child_index + old other.arity
other_is_empty: other.is_leaf
ensure then DYNAMIC_LIST
other_empty: other.is_leaf
twl_merge_right (other: like Current)
other
other
TWO_WAY_LIST
require DYNAMIC_CHAIN
extendible: child_extendible
not_after: not child_after
other_exists: other /= void
ensure DYNAMIC_CHAIN
new_count: arity = old arity + old other.arity
same_index: child_index = old child_index
other_is_empty: other.is_leaf
ensure then DYNAMIC_LIST
other_empty: other.is_leaf
merge_tree_after (other: like first_child)
other
other
require DYNAMIC_TREE
not_child_off: not child_off
other_exists: (other /= void)
ensure DYNAMIC_TREE
other_is_leaf: other.is_leaf
merge_tree_before (other: like first_child)
other
other
require DYNAMIC_TREE
not_child_off: not child_off
other_exists: (other /= void)
ensure DYNAMIC_TREE
other_is_leaf: other.is_leaf
prune (n: like first_child)
n
require TREE
is_child: n.parent = Current
ensure TREE
n_is_root: n.is_root
put (v: like item)
vitem
CELLreplace
CELL
require TREE
is_writable: writable
ensure TREE
item_inserted: item = v
ensure CELL
item_inserted: item = v
child_put (v: like child_item)
v
replace
CHAIN
require COLLECTION
extendible: child_extendible
require TREE
child_writable: child_writable
ensure COLLECTION
item_inserted: is_inserted (v)
ensure TREE
item_inserted: child_item = v
ensure then CHAIN
same_count: arity = old arity
put_child (n: like parent)
n
require else DYNAMIC_TREE
non_void_argument: n /= void
put_child_left (n: like parent)
n
require DYNAMIC_TREE
not_child_before: not child_before
non_void_argument: n /= void
put_child_right (n: like parent)
n
require DYNAMIC_TREE
not_child_after: not child_after
non_void_argument: n /= void
put_front (v: like child_item)
v
TWO_WAY_LIST
ensure DYNAMIC_CHAIN
new_count: arity = old arity + 1
item_inserted: first = v
put_i_th (v: like child_item; i: INTEGER)
vi
CHAIN
require TABLE
valid_key: valid_index (k)
ensure then INDEXABLE
insertion_done: i_th (k) = v
child_put_left (v: like child_item)
v
TWO_WAY_LIST
require DYNAMIC_CHAIN
extendible: child_extendible
not_before: not child_before
require DYNAMIC_TREE
not_child_before: not child_before
ensure DYNAMIC_CHAIN
new_count: arity = old arity + 1
new_index: child_index = old child_index + 1
ensure then LINKED_LIST
previous_exists: previous /= void
item_inserted: previous.item = v
child_put_right (v: like child_item)
v
TWO_WAY_LIST
require DYNAMIC_CHAIN
extendible: child_extendible
not_after: not child_after
require DYNAMIC_TREE
not_child_after: not child_after
ensure DYNAMIC_CHAIN
new_count: arity = old arity + 1
same_index: child_index = old child_index
ensure then LINKED_LIST
next_exists: next /= void
item_inserted: not old child_before implies next.item = v
item_inserted_before: old child_before implies child.item = v
replace (v: like item)
vitem
CELLput
CELL
require TREE
is_writable: writable
ensure TREE
item_inserted: item = v
ensure CELL
item_inserted: item = v
child_replace (v: like child_item)
v
LINKED_LIST
require ACTIVE
writable: child_writable
require TREE
child_writable: child_writable
ensure ACTIVE
item_replaced: child_item = v
ensure TREE
item_inserted: child_item = v
replace_child (n: like parent)
n
require TREE
writable_child: writable_child
was_root: n.is_root
ensure TREE
child_replaced: child = n
sprout
TREE
feature
twl_prune (v: like child_item)
v
exhausted
DYNAMIC_CHAIN
require COLLECTION
prunable: prunable
prune_all (v: like child_item)
v
object_comparison
exhausted
DYNAMIC_CHAIN
require COLLECTION
prunable
ensure COLLECTION
no_more_occurrences: not has (v)
ensure then DYNAMIC_CHAIN
is_exhausted: exhausted
remove_child
after
TWO_WAY_LIST
require ACTIVE
prunable: prunable
writable: child_writable
require DYNAMIC_TREE
child_not_off: not child_off
ensure then DYNAMIC_LIST
after_when_empty: is_leaf implies child_after
ensure DYNAMIC_TREE
new_arity: arity = old arity - 1
new_child_index: child_index = old child_index
remove_left_child
TWO_WAY_LIST
require DYNAMIC_CHAIN
left_exists: child_index > 1
require else DYNAMIC_LIST
not_before: not child_before
require DYNAMIC_TREE
is_not_first: not child_isfirst
ensure DYNAMIC_CHAIN
new_count: arity = old arity - 1
new_index: child_index = old child_index - 1
ensure DYNAMIC_TREE
new_arity: arity = old arity - 1
new_child_index: child_index = old child_index - 1
remove_right_child
TWO_WAY_LIST
require DYNAMIC_CHAIN
right_exists: child_index < arity
require DYNAMIC_TREE
is_not_last: not child_islast
ensure DYNAMIC_CHAIN
new_count: arity = old arity - 1
same_index: child_index = old child_index
ensure DYNAMIC_TREE
new_arity: arity = old arity - 1
new_child_index: child_index = old child_index
remove_sublist
TWO_WAY_LIST
split (n: INTEGER)
ncountindex
sublist
TWO_WAY_LIST
require TWO_WAY_LIST
not_off: not child_off
valid_sublist: n >= 0
wipe_out
TWO_WAY_LIST
require DYNAMIC_TREE
True
require COLLECTION
prunable
ensure COLLECTION
wiped_out: is_leaf
ensure then DYNAMIC_LIST
is_before: child_before
feature
swap (i: INTEGER)
i
CHAIN
require CHAIN
not_off: not child_off
valid_index: valid_index (i)
ensure CHAIN
swapped_to_item: child_item = old i_th (i)
swapped_from_item: i_th (i) = old child_item
feature
binary_representation: BINARY_TREE [G]
TREE
ensure TREE
result_is_root: Result.is_root
result_has_no_right_child: not Result.has_right
fill_from_binary (b: BINARY_TREE [G])
b
DYNAMIC_TREE
linear_representation: LINEAR [G]
TREE
feature
copy (other: like Current)
other
require ANY
other_not_void: other /= void
type_identity: same_type (other)
ensure ANY
is_equal: is_equal (other)
duplicate (n: INTEGER): like Current
naritychild_index
DYNAMIC_TREE
require TREE
not_child_off: not child_off
valid_sublist: n >= 0
feature
child: like first_child
LINKED_LIST
feature
do_all (action: PROCEDURE [ANY, TUPLE [G]])
action
action
LINEAR
require TRAVERSABLE
action_exists: action /= void
do_if (action: PROCEDURE [ANY, TUPLE [G]]; test: FUNCTION [ANY, TUPLE [G], BOOLEAN])
actiontest
actiontest
LINEAR
require TRAVERSABLE
action_exists: action /= void
test_exits: test /= void
for_all (test: FUNCTION [ANY, TUPLE [G], BOOLEAN]): BOOLEAN
test
LINEAR
require TRAVERSABLE
test_exits: test /= void
there_exists (test: FUNCTION [ANY, TUPLE [G], BOOLEAN]): BOOLEAN
test
LINEAR
require TRAVERSABLE
test_exits: test /= void
invariant
off_constraint: (child = void) implies child_off
ANY
reflexive_equality: standard_is_equal (Current)
reflexive_conformance: conforms_to (Current)
DYNAMIC_TREE
extendible_definition: extendible
child_after_definition: child_after = (child_index = arity + 1)
TREE
leaf_definition: is_leaf = (arity = 0)
child_off_definition: child_off = child_before or child_after
child_before_definition: child_before = (child_index = 0)
child_isfirst_definition: child_isfirst = (not is_leaf and child_index = 1)
child_islast_definition: child_islast = (not is_leaf and child_index = child_capacity)
child_after_definition: child_after = (child_index >= child_capacity + 1)
child_consistency: child_readable implies child.parent = Current
BI_LINKABLE
right_symmetry: (right_sibling /= void) implies (right_sibling.left_sibling = Current)
left_symmetry: (left_sibling /= void) implies (left_sibling.right_sibling = Current)
TWO_WAY_LIST
non_empty_list_has_two_endpoints: not is_leaf implies (first_child /= void and last_child /= void)
first_element_constraint: first_child /= void implies first_child.left_sibling = void
last_element_constraint: last_child /= void implies last_child.right_sibling = void
LINKED_LIST
prunable: prunable
empty_constraint: is_leaf implies ((first_child = void) and (child = void))
not_void_unless_empty: (child = void) implies is_leaf
before_constraint: child_before implies (child = first_child)
after_constraint: child_after implies (child = last_child)
LIST
before_definition: child_before = (child_index = 0)
after_definition: child_after = (child_index = arity + 1)
CHAIN
non_negative_index: child_index >= 0
index_small_enough: child_index <= arity + 1
off_definition: child_off = ((child_index = 0) or (child_index = arity + 1))
isfirst_definition: child_isfirst = ((not is_leaf) and (child_index = 1))
islast_definition: child_islast = ((not is_leaf) and (child_index = arity))
item_corresponds_to_index: (not child_off) implies (child_item = i_th (child_index))
index_set_has_same_count: index_set.count = arity
ACTIVE
writable_constraint: child_writable implies child_readable
empty_constraint: is_leaf implies (not child_readable) and (not child_writable)
INDEXABLE
index_set_not_void: index_set /= void
BILINEAR
not_both: not (child_after and child_before)
before_constraint: child_before implies child_off
LINEAR
after_constraint: child_after implies child_off
TRAVERSABLE
empty_constraint: is_leaf implies child_off
FINITE
empty_definition: is_leaf = (arity = 0)
non_negative_count: arity >= 0
DYNAMIC_CHAIN
extendible: child_extendible
indexing
library: "[
EiffelBase: Library of reusable components for Eiffel.
]"
status: "[
Copyright 1986-2001 Interactive Software Engineering (ISE).
For ISE customers the original versions are an ISE product
covered by the ISE Eiffel license and support agreements.
]"
license: "[
EiffelBase may now be used by anyone as FREE SOFTWARE to
develop any product, public-domain or commercial, without
payment to ISE, under the terms of the ISE Free Eiffel Library
License (IFELL) at http://eiffel.com/products/base/license.html.
]"
source: "[
Interactive Software Engineering Inc.
ISE Building
360 Storke Road, Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Electronic mail <info@eiffel.com>
Customer support http://support.eiffel.com
]"
info: "[
For latest info see award-winning pages: http://eiffel.com
]"
end -- TWO_WAY_TREE