INDEX CLUSTER FEATURES SHORT FRAMES NO FRAMES

indexing

title: "Ordered sequence of values of the conforming type ", "accessible through integer indices in a contiguous ", "interval "
project: "Visual Eiffel Library"
revision: "$Revision: 1.1 $"
copyright: "Copyright (C) 1996-2005 Object Tools Group"
license: "http://visual-eiffel.com/license"
cluster: pool
class SORTED_ARRAY [G -> COMPARABLE]
inherit

ARRAY [G]
rename
make as array_make,
resize as array_resize,
remove as array_remove,
count as array_count
export
{NONE}
array_count,
array_make,
array_remove,
array_resize
redefine
append
end
creation

fill,
init,
make
feature -- Creation

make
ensure
empty_array: count = 0

fill (arr: ARRAY [G])
require
non_void_array: arr /= void
valid_lower: arr.lower = 1
array_sorted: is_sorted (arr)
ensure
the_same_capacity: arr.count = count

init (a: ARRAY [G])
require
non_void_array: a /= void
feature -- Measurement

count: INTEGER
-- Number of items in the array
ensure
non_negative_count: Result >= 0
feature -- Operations

append (arr: like Current)
-- Allows to append one SORTED_ARRAY (may be Void) to another

substract (arr: like Current)
-- Allows to substract one SORTED_ARRAY (may be Void) from the current.
feature -- Removal

delete (pos: INTEGER)
require
positive_pos: pos > 0
valid_pos: pos <= count
ensure
count_decreased: count = count - 1

remove (x: G)
require
non_void_element: x /= void

removed (x: G): BOOLEAN
require
non_void_element: x /= void
ensure
done: Result implies (count = count - 1)
absent: not Result implies (count = count )
feature -- Element change

append_item (x: G)
require
non_void_element: x /= void
largest_element: count > 0 implies item (count) < x

add (x: G)
require
non_void_element: x /= void

added (x: G): BOOLEAN
require
non_void_element: x /= void
ensure
done: Result implies (count = count + 1)

replace (x: G)
require
non_void_element: x /= void

add_after (x: G; pos: INTEGER)
require
non_void_element: x /= void
negative_position: pos <= 0
valid_position: - pos <= count
ensure
added: seek (x) = - pos + 1

add_it (x: G): G
require
non_void_element: x /= void
feature -- Searching

search (x: G): like x
-- Search for an element that is equal to `x'
-- Return default value (i.e. Void for reference types) if not found
require
non_void_element: x /= void

seek (x: G): INTEGER
-- This is used to add new elements into the array.
-- Allows to test if the element is present in the structure or
-- where it should be put. So if there is no such an
-- element in the structure seek will return negative number which means
-- the position after which this element must be in the order of the sort.
require
non_void_element: x /= void
feature -- Resizing

resize (n: INTEGER)
require
good_array_size: n >= 0 and then n <= count
feature -- Conversion

to_array: ARRAY [G]
feature -- Sorting

qsort
invariant

sorted:
end -- class SORTED_ARRAY

INDEX CLUSTER FEATURES SHORT FRAMES NO FRAMES