INDEX CLUSTER FEATURES SHORT FRAMES NO FRAMES

indexing

title: "Tables: containers with two element entries (element or", "item itself and the associated key) implementing a FIFO", "policy and supporting traversal in the both directions"
project: "Visual Eiffel"
revision: "$Revision: 1.2 $"
copyright: "Copyright (C) 1996-2005 Object Tools Group"
license: "http://visual-eiffel.com/license"
cluster: containers
class TABLE_ [G, H]
inherit

KEYED_CONTAINER_ [G, H]
end

TRAVERSABLE_
end
creation

make
feature -- Operations

allocate_automatically
-- switches the table to the mode of automatic memory allocation
-- for new slots; it can be necessary only if 'allocate_manually'
-- was called before because, by default, all types of the tables
-- allocate memory automatically

allocate_manually (new_capacity: INTEGER)
-- forbids the table to allocate memory for new slots automatically
-- and sets the total amount of slots allocated in the table to be
-- equal to 'new_capacity' - being negligent after that in manual
-- allocating extra slots for new entries to be put might lead to
-- the exception of type SCIF ("container is full")
--
require
no_obstacle: not is_protected
proper_argument: new_capacity >= count and then new_capacity > 0

make (is_unique: BOOLEAN)
-- tells the container if the keys of its entries must be unigue

merge (x: like Current)
-- puts all entries from 'other' into the table
require
no_obstacle: not is_protected
valid_argument: x /= void
ensure
well_done: count = guide.count

put (x: G; k: H)
-- adds the new entry into the structure
require
valid_item: x /= void
valid_key: k /= void
no_obstacle: not is_protected
uniqueness: unique_keys implies not has_key (k)
is_not_full: no_reallocation implies count < capacity
ensure
well_done: not empty and then has_key (k) and then count = guide.count

remove (x: G; k: H)
-- deletes the entry from the table
require
no_obstacle: not is_protected
valid_item: x /= void
proper_key: k /= void and then has_key (k)
ensure
well_done: count = guide.count

remove_all (k: H)
-- deletes all the entries items of which associated with key 'k'
require
no_obstacle: not is_protected
proper_key: k /= void and then has_key (k)
ensure
well_done: not has_key (k) and then count = guide.count

search (k: H)
-- looks for the key: after every successful attempt 'found' is
-- set to true and 'found_item' - to an element (item) associated
-- with key 'k'; in case of failure 'found' is set to false
require
valid_argument: k /= void

wipe_out
-- remove all entries from the table
require
no_obstacle: not is_protected
ensure
well_done: empty and then count = guide.count
feature -- Queries

count: INTEGER

found: BOOLEAN

found_item: G

unique_keys: BOOLEAN

capacity: INTEGER
-- gives the number of all slots allocated in the table (all types
-- of the tables may have not only slots occupied by the entries
-- already put into but unused ones also)

count_of (k: H): INTEGER
-- gives the number of the entries items of which associated with
-- key 'k'; if 'unique_items = true' then the number can be equal
-- only to zero or one
require
valid_key: k /= void
ensure
well_done: Result <= count

current_keys: LIST_ [H]
-- delivers all the keys (without duplicates) currently stored in
-- the table

cursor_at (x: G; k: H): CURSOR_
-- delivers a new cursor positioned to the entry; if there is no
-- such entry currently stored in the table Void is delivered
require
valid_item: x /= void
proper_key: k /= void
ensure
well_done: Result /= void implies is_protected

has_key (k: H): BOOLEAN
-- is the entry currently stored in the table ?
require
valid_key: k /= void

item_at (cs: CURSOR_): G
-- delivers the element or item of the entry the cursor is
-- positioned to
require
proper_cursor: is_inside (cs)

items_at_key (k: H): LIST_ [G]
-- delivers all the elements (items) currently stored in the
-- table and associated with key 'k'
require
proper_key: k /= void

key_at (cs: CURSOR_): H
-- the key of the entry the cursor is positioned to
require
proper_cursor: is_inside (cs)
invariant

nothing_lost: capacity = count + guide.stock
properly_tuned: capacity = guide.capacity
is_ordered: guide /= void and then guide.target = Current
end -- class TABLE_

INDEX CLUSTER FEATURES SHORT FRAMES NO FRAMES