indexing
description: "Trees where the children of each node are kept in an array"
status: "See notice at end of class"
names: tree
representation: recursive, array
access: cursor, membership
contents: generic
date: "$Date$"
revision: "$Revision$"
class interface
ARRAYED_TREE [G]
create
make (n: INTEGER; v: G)
v
n
require
valid_number_of_children: n >= 0
ensure
node_item: item = v
feature
make (n: INTEGER; v: G)
v
n
require
valid_number_of_children: n >= 0
ensure
node_item: item = v
make_filled (n: INTEGER)
n
n
ARRAYED_LIST
require ARRAYED_LIST
valid_number_of_items: n >= 0
ensure ARRAYED_LIST
correct_position: child_before
filled: al_full
make_from_array (a: ARRAY [ARRAYED_TREE [G]])
a
ARRAYED_LIST
require ARRAY
array_exists: a /= void
feature
child_item: like item
TREE
require TREE
readable: child_readable
child_cursor: CURSOR
ARRAYED_LIST
first_child: ARRAYED_TREE [G]
ARRAYED_LIST
require CHAIN
not_empty: not is_leaf
require TREE
is_not_leaf: not is_leaf
child_index: INTEGER
item
ARRAYED_LIST
index_of (v: like child; i: INTEGER): INTEGER
iv
object_comparison
CHAIN
require LINEAR
positive_occurrences: i > 0
ensure LINEAR
non_negative_result: Result >= 0
item: G
CELL
child: like first_child
ARRAYED_LIST
require TRAVERSABLE
not_off: not child_off
require ACTIVE
readable: readable_child
require TREE
readable: readable_child
require else ARRAYED_LIST
index_is_valid: valid_index (child_index)
array_item (i: INTEGER): ARRAYED_TREE [G]
i
ARRAY@
ARRAY
require TABLE
valid_key: array_valid_index (k)
last_child: like first_child
ARRAYED_LIST
require CHAIN
not_empty: not is_leaf
require TREE
is_not_leaf: not is_leaf
left_sibling: like parent
require TREE
is_not_root: not is_root
ensure TREE
is_sibling: Result /= void implies is_sibling (Result)
right_is_current: (Result /= void) implies (Result.right_sibling = Current)
sequential_occurrences (v: ARRAYED_TREE [G]): INTEGER
v
object_comparison
LINEAR
ensure BAG
non_negative_occurrences: Result >= 0
parent: ARRAYED_TREE [G]
right_sibling: like parent
require TREE
is_not_root: not is_root
ensure TREE
is_sibling: Result /= void implies is_sibling (Result)
left_is_current: (Result /= void) implies (Result.left_sibling = Current)
infix "@" (i: INTEGER): ARRAYED_TREE [G]
i
ARRAYitem
ARRAY
require TABLE
valid_key: array_valid_index (k)
feature
child_capacity: INTEGER
TREE
count: INTEGER
TREE
arity: INTEGER
ARRAYED_LIST
index_set: INTEGER_INTERVAL
CHAIN
ensure INDEXABLE
not_void: Result /= void
ensure then CHAIN
count_definition: Result.count = arity
occurrences (v: like child): INTEGER
v
object_comparison
CHAIN
ensure BAG
non_negative_occurrences: Result >= 0
occurrences (v: like child): INTEGER
v
object_comparison
CHAIN
ensure BAG
non_negative_occurrences: Result >= 0
feature
capacity: INTEGER
ARRAYcount
ARRAY
ensure then ARRAY
consistent_with_bounds: Result = upper - lower + 1
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
LIST
child_before: BOOLEAN
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
Al_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: ARRAYED_TREE [G]): BOOLEAN
vput
extend
ARRAYED_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
CHAIN
prunable: BOOLEAN
ARRAYED_LIST
Readable: BOOLEAN is True
TREE
readable_child: BOOLEAN
SEQUENCE
valid_cursor (p: CURSOR): BOOLEAN
p
ARRAYED_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
ARRAYED_LIST
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))
valid_index (i: INTEGER): BOOLEAN
i
ARRAYED_LIST
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
SEQUENCE
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
ARRAYED_LIST
require TREE
True
require BILINEAR
not_before: not child_before
child_finish
ARRAYED_LIST
ensure then CHAIN
at_last: not is_leaf implies child_islast
ensure then TREE
is_last_child: not is_leaf implies child_islast
ensure then ARRAYED_LIST
before_when_empty: is_leaf implies child_before
child_forth
ARRAYED_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
ARRAYED_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
ARRAYED_LIST
require TREE
True
require CURSOR_STRUCTURE
cursor_position_valid: valid_cursor (p)
move (i: INTEGER)
i
ARRAYED_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)
search_child (v: like child)
itemv
v
exhausted
object_comparison
BILINEAR
ensure LINEAR
object_found: (not exhausted and object_comparison) implies equal (v, child)
item_found: (not exhausted and not object_comparison) implies v = child
child_start
ARRAYED_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 ARRAYED_LIST
after_when_empty: is_leaf implies child_after
feature
append (s: SEQUENCE [ARRAYED_TREE [G]])
s
SEQUENCE
require SEQUENCE
argument_not_void: s /= void
ensure SEQUENCE
new_count: arity >= old arity
child_extend (v: like item)
v
child_put (v: like item)
v
ARRAYED_TREEchild_replace
require TREE
child_writable: child_writable
ensure TREE
item_inserted: child_item = v
child_put_left (v: like item)
v
require DYNAMIC_TREE
not_child_before: not child_before
child_put_right (v: like item)
v
require DYNAMIC_TREE
not_child_after: not child_after
child_replace (v: like item)
v
ARRAYED_TREEchild_put
require TREE
child_writable: child_writable
ensure TREE
item_inserted: child_item = v
fill (other: TREE [G])
other
other
TREE
force (v: like child)
v
ARRAYED_LISTextend
ARRAYED_LIST
require SEQUENCE
extendible: al_extendible
ensure then SEQUENCE
new_count: arity = old arity + 1
item_inserted: has (v)
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
put_i_th (v: like array_item; i: INTEGER)
iv
ARRAY
require TABLE
valid_key: array_valid_index (k)
ensure then INDEXABLE
insertion_done: array_item (k) = v
put (v: like item)
vitem
CELLreplace
CELL
require TREE
is_writable: writable
ensure TREE
item_inserted: item = v
ensure CELL
item_inserted: item = v
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)
v
ARRAYED_LIST
ensure DYNAMIC_CHAIN
new_count: arity = old arity + 1
item_inserted: first_child = 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
replace_child (n: like parent)
n
require TREE
writable_child: writable_child
was_root: n.is_root
ensure TREE
child_replaced: child = n
ensure then
child_replaced: n.parent = Current
sprout
TREE
feature
prune (v: like child)
v
afterv
ARRAYED_LIST
require COLLECTION
prunable: prunable
require TREE
is_child: n.parent = Current
ensure TREE
n_is_root: n.is_root
prune_all (v: like child)
v
object_comparison
ARRAYED_LIST
require COLLECTION
prunable
ensure COLLECTION
no_more_occurrences: not has (v)
ensure then DYNAMIC_CHAIN
is_exhausted: exhausted
ensure then ARRAYED_LIST
is_after: child_after
remove_child
after
require DYNAMIC_TREE
child_not_off: not child_off
ensure DYNAMIC_TREE
new_arity: arity = old arity - 1
new_child_index: child_index = old child_index
remove_left_child
require DYNAMIC_TREE
is_not_first: not child_isfirst
ensure DYNAMIC_TREE
new_arity: arity = old arity - 1
new_child_index: child_index = old child_index - 1
remove_right_child
require DYNAMIC_TREE
is_not_last: not child_islast
ensure DYNAMIC_TREE
new_arity: arity = old arity - 1
new_child_index: child_index = old child_index
wipe_out
ARRAYED_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
ARRAYED_LIST
require CHAIN
not_off: not child_off
valid_index: array_valid_index (i)
ensure CHAIN
swapped_to_item: child = old array_item (i)
swapped_from_item: array_item (i) = old child
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)
ensure then ARRAY
equal_areas: area.is_equal (other.area)
duplicate (n: INTEGER): like Current
naritychild_index
require TREE
not_child_off: not child_off
valid_sublist: n >= 0
feature
do_all (action: PROCEDURE [ANY, TUPLE [ARRAYED_TREE [G]]])
action
action
LINEAR
require TRAVERSABLE
action_exists: action /= void
do_if (action: PROCEDURE [ANY, TUPLE [ARRAYED_TREE [G]]]; test: FUNCTION [ANY, TUPLE [ARRAYED_TREE [G]], BOOLEAN])
actiontest
actiontest
LINEAR
require TRAVERSABLE
action_exists: action /= void
test_exits: test /= void
for_all (test: FUNCTION [ANY, TUPLE [ARRAYED_TREE [G]], BOOLEAN]): BOOLEAN
test
LINEAR
require TRAVERSABLE
test_exits: test /= void
there_exists (test: FUNCTION [ANY, TUPLE [ARRAYED_TREE [G]], BOOLEAN]): BOOLEAN
test
LINEAR
require TRAVERSABLE
test_exits: test /= void
invariant
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
ARRAYED_LIST
prunable: prunable
starts_from_one: lower = 1
empty_means_storage_empty: is_leaf implies all_default
ARRAY
area_exists: area /= void
consistent_size: capacity = upper - lower + 1
non_negative_count: arity >= 0
index_set_has_same_count: valid_index_set
RESIZABLE
increase_by_at_least_one: minimal_increase >= 1
BOUNDED
valid_count: arity <= capacity
full_definition: al_full = (arity = capacity)
FINITE
empty_definition: is_leaf = (arity = 0)
non_negative_count: arity >= 0
INDEXABLE
index_set_not_void: index_set /= void
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 = array_item (child_index))
index_set_has_same_count: index_set.count = arity
ACTIVE
writable_constraint: writable_child implies readable_child
empty_constraint: is_leaf implies (not readable_child) and (not writable_child)
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
DYNAMIC_CHAIN
extendible: al_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 -- ARRAYED_TREE