INDEX CLUSTER FEATURES SHORT FRAMES NO FRAMES

indexing

description: "Hash tables, used to store items identified by hashable keys"
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 "
cluster: eiffelbase
class HASH_TABLE [G, H -> HASHABLE]
inherit

UNBOUNDED [G]
rename
has as has_item
redefine
copy,
is_equal
end

TABLE [G, H]
rename
has as has_item,
wipe_out as clear_all
export
{NONE}
prune_all
redefine
copy,
is_equal
end
creation

make
feature -- Initialization

make (n: INTEGER)
-- Allocate hash table for at least `n' items.
-- The table will be resized automatically
-- if more than `n' items are inserted.
ensure
capacity_big_enough: capacity >= n and capacity >= minimum_size
feature -- Access

item, infix "@" (key: H): G
-- Item associated with `key', if present
-- otherwise default value of type `G'

has (key: H): BOOLEAN
-- Is there an item in the table with key `key'?

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

current_keys: ARRAY [H]
-- Array of actually used keys, from 1 to `count'
ensure
good_count: Result.count = count

item_for_iteration: G
-- Element at current iteration position
require
not_off: not off

key_for_iteration: H
-- Key at current iteration position
require
not_off: not off

search_item: G

cursor: CURSOR
-- Current cursor position
ensure
cursor_not_void: Result /= void
feature -- Measurement

count: INTEGER

capacity: INTEGER
feature -- Comparison

is_equal (other: like Current): BOOLEAN
-- Does table contain the same information as `other'?
feature -- Status report

full: BOOLEAN

extendible: BOOLEAN

prunable: BOOLEAN
-- May items be removed? (Answer: yes.)

conflict: BOOLEAN
-- Did last operation cause a conflict?

inserted: BOOLEAN
-- Did last operation insert an item?

replaced: BOOLEAN
-- Did last operation replace an item?

removed: BOOLEAN
-- Did last operation remove an item?

found: BOOLEAN
-- Did last operation find the item sought?

after, off: BOOLEAN
-- Is cursor past last item?

valid_cursor (c: CURSOR): BOOLEAN
-- Can cursor be moved to position `c'?
require
c_not_void: c /= void
feature -- Cursor movement

start
-- Bring cursor to first position.

forth
-- Advance cursor to next occupied position.
require
not_off: not off

go_to (c: CURSOR)
-- Move to position `c'.
require
c_not_void: c /= void
valid_cursor: valid_cursor (c)

search (key: H)
-- Search for item of key `key'.
-- If found, set `found' to true and `search_item' to item for `key'.
feature -- Element change

put (new: G; key: H)
-- Insert `new' with `key' if there is no other item
-- associated with the same key.
-- Make `inserted' true if and only if an insertion has
-- been made (i.e. `key' was not present).
-- If so, set `position' to the insertion position.
ensure
insertion_done: inserted implies item (key) = new
one_more_if_inserted: inserted implies (count = count + 1)
unchanged_if_conflict: conflict implies (count = count )

force (new: G; key: H)
-- If `key' is present, replace corresponding item by `new',
-- if not, insert item `new' with key `key'.
-- Make `inserted' true.
require
true
ensure
insertion_done: item (key) = new
same_count_or_one_more: (count = count ) or (count = count + 1)
inserted: inserted

replace (new: G; key: H)
-- Replace item at `key', if present,
-- with `new'; do not change associated key.
-- Make `replaced' true if and only if a replacement has
-- been made (i.e. `key' was present).
ensure
insertion_done: replaced implies item (key) = new

replace_key (new_key: H; old_key: H)
-- If there is an item of key `old_key' and no item of key
-- `new_key', replace the former's key by `new_key'
-- and set status to `replaced'.
ensure
old_absent: (replaced and not equal (new_key, old_key)) implies (not has (old_key))
new_present: replaced implies (has (new_key))
same_count: count = count
feature -- Removal

remove (key: H)
-- Remove item associated with `key', if present.
-- Make `removed' true if and only if an item has been
-- removed (i.e. `key' was present).
-- If so, set `position' to index of removed element.
ensure
not_there: not has (key)
one_less: found implies (count = count - 1)

clear_all
-- Reset all items to default values.
ensure
position_equal_to_zero: position = 0
count_equal_to_zero: count = 0
has_default_set: not has_default
status_set: control = 0
feature -- Conversion

linear_representation: ARRAYED_LIST [G]
-- Representation as a linear structure
-- (order is same as original order of insertion)
ensure
result_exists: Result /= void
good_count: Result.count = count
feature -- Duplication

copy (other: like Current)
-- Re-initialize from `other'.
feature -- Obsolete

dead_key: H
obsolete "this special key is no more used"

pos_for_iter: INTEGER
obsolete "use iteration_position"

changed_constant: INTEGER
obsolete "use Replaced_constant"

valid_key (k: H): BOOLEAN
obsolete "The default value is now accepted"
-- Is `k' a valid key?
-- Answer: yes
ensure
Result
invariant

keys_not_void: keys /= void
content_not_void: content /= void
count_big_enough: 0 <= count
count_small_enough: count <= capacity
keys_same_capacity_plus_one: keys.count = capacity + 1
content_same_capacity_plus_one: content.count = capacity + 1
deleted_same_capacity: deleted_marks.count = capacity
keys_starts_at_zero: keys.lower = 0
content_starts_at_zero: content.lower = 0
deleted_starts_at_zero: deleted_marks.lower = 0
valid_iteration_position: off or truly_occupied (iteration_position)
end -- class HASH_TABLE

INDEX CLUSTER FEATURES SHORT FRAMES NO FRAMES