INDEX CLUSTER FEATURES SHORT FRAMES NO FRAMES

indexing

description: "Possibly circular sequences of items, ", "without commitment to a particular representation "
title: "EiffelBase: library of reusable components for Eiffel. ", "Based on EiffelBase library for ISE Eiffel, ", "used with permission. "
project: "EiffelBase Library"
copyright: "(c) 1986-1997 Interactive Software Engineering Inc. ", "Modifications and extensions: ", "(c) 1997 Object Tools ", "All rights reserved. Duplication and distribution prohibited", "May be used only with Visual Eiffel under terms of user ", "license "
key: chain, sequence
cluster: eiffelbase
deferred class CHAIN [G]
inherit

CURSOR_STRUCTURE [G]
undefine
prune_all
select
put
end

INDEXABLE [G, INTEGER]
rename
item as i_th,
put as put_i_th
undefine
prune_all
end

SEQUENCE [G]
rename
put as sequence_put
export
{NONE}
sequence_put
redefine
has,
index,
index_of,
occurrences,
off
select
has,
index_of,
occurrences
end

SEQUENCE [G]
rename
put as sequence_put,
index_of as sequential_index_of,
has as sequential_has,
occurrences as sequential_occurrences
export
{NONE}
sequence_put,
sequential_has,
sequential_index_of
redefine
index,
off
end
feature -- Access

first: like item
-- Item at first position
require
not_empty: not empty

last: like item
-- Item at last position
require
not_empty: not empty

has (v: G): BOOLEAN
-- Does chain include `v'?
-- (Reference or object equality,
-- based on `object_comparison'.)

index_of (v: G; i: INTEGER): INTEGER
-- Index of `i'-th occurrence of item identical to `v'.
-- (Reference or object equality,
-- based on `object_comparison'.)
-- 0 if none.

i_th, infix "@" (i: INTEGER): G
-- Item at `i'-th position

index: INTEGER
-- Current cursor index

occurrences (v: G): INTEGER
-- Number of times `v' appears.
-- (Reference or object equality,
-- based on `object_comparison'.)
feature -- Cursor movement

start
-- Move cursor to first position.
-- (No effect if empty)
ensure
at_first: not empty implies isfirst

finish
-- Move cursor to last position.
-- (No effect if empty)
ensure
at_last: not empty implies islast

move (i: INTEGER)
-- Move cursor `i' positions. The cursor
-- may end up `off' if the absolute value of `i'
-- is too big.
ensure
too_far_right: ( index + i > count) implies exhausted
too_far_left: ( index + i < 1) implies exhausted
expected_index: (not exhausted) implies (index = index + i)

go_i_th (i: INTEGER)
-- Move cursor to `i'-th position.
require
valid_cursor_index: valid_cursor_index (i)
ensure
position_expected: index = i
feature -- Status report

valid_index (i: INTEGER): BOOLEAN
-- Is `i' within allowable bounds?
ensure
valid_index_definition: Result = ((i >= 1) and (i <= count))

isfirst: BOOLEAN
-- Is cursor at first position?
ensure
valid_position: Result implies not empty

islast: BOOLEAN
-- Is cursor at last position?
ensure
valid_position: Result implies not empty

off: BOOLEAN
-- Is there no current item?

valid_cursor_index (i: INTEGER): BOOLEAN
-- Is `i' correctly bounded for cursor movement?
ensure
valid_cursor_index_definition: Result = ((i >= 0) and (i <= count + 1))
feature -- Element change

put (v: G)
-- Replace current item by `v'.
-- (Synonym for `replace')
ensure
same_count: count = count

put_i_th (v: G; i: INTEGER)
-- Put `v' at `i'-th position.
feature -- Transformation

swap (i: INTEGER)
-- Exchange item at `i'-th position with item
-- at cursor position.
require
not_off: not off
valid_index: valid_index (i)
ensure
swapped_to_item: item = i_th (i)
swapped_from_item: i_th (i) = item
feature -- Duplication

duplicate (n: INTEGER): like Current
-- Copy of sub-chain beginning at current position
-- and having min (`n', `from_here') items,
-- where `from_here' is the number of items
-- at or to the right of current position.
require
not_off_unless_after: off implies after
valid_subchain: n >= 0
invariant

non_negative_index: index >= 0
index_small_enough: index <= count + 1
off_definition: off = ((index = 0) or (index = count + 1))
isfirst_definition: isfirst = ((not empty) and (index = 1))
islast_definition: islast = ((not empty) and (index = count))
item_corresponds_to_index: (not off) implies (item = i_th (index))
end -- class CHAIN

INDEX CLUSTER FEATURES SHORT FRAMES NO FRAMES