Class DS_BILINEAR PreviousNext

note
description:

    "Data structures that can be traversed forward and backward"

library:    "Gobo Eiffel Structure Library"
author:     "Eric Bezault <ericb@gobosoft.com>"
copyright:  "Copyright (c) 1999-2001, Eric Bezault and others"
license:    "MIT License"
deferred class interface
DS_BILINEAR [G]
inherit
DS_LINEAR [G]
    DS_TRAVERSABLE [G]
        DS_CONTAINER [G]
    DS_SEARCHABLE [G]
        DS_CONTAINER [G]
feature {NONE} -- Initialization
make_default
        -- Create an empty container.
        -- (From DS_CONTAINER.)
    deferred
    ensure
        empty: is_empty
feature -- Access
item_for_iteration: G
        -- Item at internal cursor position
        -- (From DS_TRAVERSABLE.)
    require
        not_off: not off
first: G
        -- First item in container
        -- (From DS_LINEAR.)
    require
        not_empty: not is_empty
    deferred
    ensure
        has_first: has (Result)
last: G
        -- Last item in container
    require
        not_empty: not is_empty
    deferred
    ensure
        has_last: has (Result)
new_cursor: DS_BILINEAR_CURSOR [G]
        -- New external cursor for traversal
        -- (From DS_TRAVERSABLE.)
    deferred
    ensure
        cursor_not_void: Result /= Void
        valid_cursor: valid_cursor (Result)
equality_tester: DS_EQUALITY_TESTER [G]
        -- Equality tester;
        -- A void equality tester means that `='
        -- will be used as comparison criterion.
        -- (From DS_SEARCHABLE.)
feature -- Measurement
count: INTEGER
        -- Number of items in container
        -- (From DS_CONTAINER.)
    deferred
occurrences (v: G): INTEGER
        -- Number of times v appears in container
        -- (Use equality_tester's comparison criterion
        -- if not void, use `=' criterion otherwise.)
        -- (From DS_SEARCHABLE.)
    ensure
        positive: Result >= 0
        has: has (v) implies Result >= 1
feature -- Status report
has (v: G): BOOLEAN
        -- Does container include v?
        -- (Use equality_tester's comparison criterion
        -- if not void, use `=' criterion otherwise.)
        -- (From DS_SEARCHABLE.)
    ensure
        not_empty: Result implies not is_empty
is_empty: BOOLEAN
        -- Is container empty?
        -- (From DS_CONTAINER.)
is_first: BOOLEAN
        -- Is internal cursor on first item?
        -- (From DS_LINEAR.)
    ensure
        not_empty: Result implies not is_empty
        not_off: Result implies not off
        definition: Result implies (item_for_iteration = first)
is_last: BOOLEAN
        -- Is internal cursor on last item?
    ensure
        not_empty: Result implies not is_empty
        not_off: Result implies not off
        definition: Result implies (item_for_iteration = last)
after: BOOLEAN
        -- Is there no valid position to right of internal cursor?
        -- (From DS_LINEAR.)
before: BOOLEAN
        -- Is there no valid position to left of internal cursor?
off: BOOLEAN
        -- Is there no item at internal cursor position?
        -- (From DS_TRAVERSABLE.)
same_position (a_cursor: like new_cursor): BOOLEAN
        -- Is internal cursor at same position as a_cursor?
        -- (From DS_TRAVERSABLE.)
    require
        a_cursor_not_void: a_cursor /= Void
valid_cursor (a_cursor: DS_CURSOR [G]): BOOLEAN
        -- Is a_cursor a valid cursor?
        -- (From DS_TRAVERSABLE.)
    require
        a_cursor_not_void: a_cursor /= Void
same_items (v, u: G): BOOLEAN
        -- Are v and u considered equal?
        -- (Use equality_tester's comparison criterion
        -- if not void, use `=' criterion otherwise.)
        -- (From DS_SEARCHABLE.)
same_equality_tester (other: DS_SEARCHABLE [G]): BOOLEAN
        -- Does container use the same comparison
        -- criterion as other?
        -- (From DS_SEARCHABLE.)
    require
        other_not_void: other /= Void
equality_tester_settable (a_tester: like equality_tester): BOOLEAN
        -- Can set_equality_tester be called with a_tester
        -- as argument in current state of container?
        -- (Default answer: True.)
        -- (From DS_SEARCHABLE.)
feature -- Comparison
is_equal (other: like Current): BOOLEAN
        -- Is current container equal to other?
        -- (From GENERAL.)
    require
        other_not_void: other /= Void
    deferred
    ensure
        consistent: standard_is_equal (other) implies Result
        same_type: Result implies same_type (other)
        symmetric: Result implies other.is_equal (Current)
        same_count: Result implies count = other.count
feature -- Duplication
copy (other: like Current)
        -- Copy other to current container.
        -- (From GENERAL.)
    require
        other_not_void: other /= Void
        type_identity: same_type (other)
    deferred
    ensure
        is_equal: is_equal (other)
feature -- Setting
set_equality_tester (a_tester: like equality_tester)
        -- Set equality_tester to a_tester.
        -- A void equality tester means that `='
        -- will be used as comparison criterion.
        -- (From DS_SEARCHABLE.)
    require
        equality_tester_settable: equality_tester_settable (a_tester)
    ensure
        equality_tester_set: equality_tester = a_tester
feature -- Cursor movement
start
        -- Move internal cursor to first position.
        -- (From DS_LINEAR.)
    ensure
        empty_behavior: is_empty implies after
        not_empty_behavior: not is_empty implies is_first
finish
        -- Move internal cursor to last position.
    ensure
        empty_behavior: is_empty implies before
        not_empty_behavior: not is_empty implies is_last
forth
        -- Move internal cursor to next position.
        -- (From DS_LINEAR.)
    require
        not_after: not after
back
        -- Move internal cursor to previous position.
    require
        not_before: not before
search_forth (v: G)
        -- Move internal cursor to first position at or after current
        -- position where item_for_iteration and v are equal.
        -- (Use equality_tester's comparison criterion
        -- if not void, use `=' criterion otherwise.)
        -- Move after if not found.
        -- (From DS_LINEAR.)
    require
        not_off: not off or after
search_back (v: G)
        -- Move internal cursor to first position at or before current
        -- position where item_for_iteration and v are equal.
        -- (Use equality_tester's comparison criterion
        -- if not void, use `=' criterion otherwise.)
        -- Move before if not found.
    require
        not_off: not off or before
go_after
        -- Move cursor to after position.
        -- (From DS_LINEAR.)
    ensure
        after: after
go_before
        -- Move cursor to before position.
    ensure
        before: before
go_to (a_cursor: like new_cursor)
        -- Move internal cursor to a_cursor's position.
        -- (From DS_TRAVERSABLE.)
    require
        cursor_not_void: a_cursor /= Void
        valid_cursor: valid_cursor (a_cursor)
    ensure
        same_position: same_position (a_cursor)
feature -- Removal
wipe_out
        -- Remove all items from container.
        -- (From DS_CONTAINER.)
    deferred
    ensure
        wiped_out: is_empty
invariant
positive_count: count >= 0
empty_definition: is_empty = (count = 0)
    -- (From DS_CONTAINER.)
empty_constraint: is_empty implies off
    -- (From DS_TRAVERSABLE.)
after_constraint: after implies off
    -- (From DS_LINEAR.)
not_both: not (after and before)
before_constraint: before implies off
end -- class DS_BILINEAR

Copyright © 1999-2001, Eric Bezault
mailto:
ericb@gobosoft.com
http:
//www.gobosoft.com
Last Updated: 31 March 2001

HomeTocPreviousNext