Class DS_LINEAR PreviousNext

note
description:

    "Data structures that may be traversed forward"

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_LINEAR [G]
inherit
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
    require
        not_empty: not is_empty
    deferred
    ensure
        has_first: has (Result)
new_cursor: DS_LINEAR_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?
    ensure
        not_empty: Result implies not is_empty
        not_off: Result implies not off
        definition: Result implies (item_for_iteration = first)
after: BOOLEAN
        -- Is there no valid position to right 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.
    ensure
        empty_behavior: is_empty implies after
        not_empty_behavior: not is_empty implies is_first
forth
        -- Move internal cursor to next position.
    require
        not_after: not after
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.
    require
        not_off: not off or after
go_after
        -- Move cursor to after position.
    ensure
        after: after
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
end -- class DS_LINEAR

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

HomeTocPreviousNext