<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://dev.eiffel.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Kenga</id>
		<title>EiffelStudio: an EiffelSoftware project - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://dev.eiffel.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Kenga"/>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/Special:Contributions/Kenga"/>
		<updated>2026-04-19T04:55:33Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.24.1</generator>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=15154</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=15154"/>
				<updated>2014-04-30T11:04:53Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Iterators */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library, which has for many years played a central role in Eiffel development.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
The latest version of the EiffelBase2 source code is available from the repository: [https://bitbucket.org/nadiapolikarpova/eiffelbase2/ https://bitbucket.org/nadiapolikarpova/eiffelbase2/]&lt;br /&gt;
&lt;br /&gt;
The source code is divided into two clusters:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;structures&amp;lt;/e&amp;gt; - Data Structures, the core of EiffelBase2. The rest of current document is about this cluster.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;mml&amp;lt;/e&amp;gt; - Mathematical Model Library: a library of immutable classes used in ''model-based contracts'' (see below).&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Complete specifications. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
On the top level EiffelBase2 differentiates between ''containers'' and ''streams''. A container is a finite storage of values, while a stream provides linear access to a set of values. A stream is not necessarily bound to a container, e.g. &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; stream observes an infinite sequence of pseudo-random numbers. Streams that traverse containers are called ''iterators''.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies: containers and streams/iterators. &lt;br /&gt;
All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity.&lt;br /&gt;
&lt;br /&gt;
In the diagrams below asterisk and italics font indicates a &amp;lt;e&amp;gt;deferred&amp;lt;/e&amp;gt; class.&lt;br /&gt;
Lighter fill color indicates that the class provides an ''immutable'' interface to the data,&lt;br /&gt;
in other words, it is impossible to modify the content of the container using this interface.&lt;br /&gt;
 &lt;br /&gt;
[[Image:eb2_container.png|1000px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
[[Image:eb2_iterator.png|1000px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
==Usage examples==&lt;br /&gt;
&lt;br /&gt;
===Immutable interfaces===&lt;br /&gt;
With immutable interfaces you can give your clients read-only access to a container you store:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
class TRAM_LINE&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    &lt;br /&gt;
    stations: V_SEQUENCE [STATION]&lt;br /&gt;
            -- Stations on the line.&lt;br /&gt;
            -- (Clients can traverse the stations, but cannot replace them, remove or add new ones.)&lt;br /&gt;
        do&lt;br /&gt;
            Result := station_list&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
feature {NONE} -- Implementation&lt;br /&gt;
&lt;br /&gt;
    station_list: V_LIST [STATION]&lt;br /&gt;
            -- List of line stations.&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Iterators===&lt;br /&gt;
Here is how you can iterate through any container:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    do&lt;br /&gt;
        across&lt;br /&gt;
            container as i&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)            &lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same thing using the explicit syntax:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        from&lt;br /&gt;
            i := container.new_cursor&lt;br /&gt;
        until&lt;br /&gt;
            i.after&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is some more advanced stuff you can do with lists:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (list: V_LIST [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_LIST_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Find the last 0 at or before position 5:&lt;br /&gt;
        list.at (5).search_back (0)&lt;br /&gt;
        -- Find the first positive element at or after position 5:&lt;br /&gt;
        i := list.at (5)&lt;br /&gt;
        i.satisfy_forth (agent (x: INTEGER): BOOLEAN do Result := x &amp;gt; 0 end)&lt;br /&gt;
        -- And insert a 0 after it:&lt;br /&gt;
        i.extend_right (0)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Sets and tables===&lt;br /&gt;
&lt;br /&gt;
Here is how you create and use a simple hash table (keys must inherit from HASHABLE):&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create table.with_object_equality&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;cat&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you need a custom hash function or equivalence relation on keys, you can use V_GENERAL_HASH_TABLE, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_GENERAL_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Create case-insensitive table:&lt;br /&gt;
        create table.make (&lt;br /&gt;
            agent {STRING}.is_case_insensitive_equal,&lt;br /&gt;
            agent (s: STRING): INTEGER do Result := s.as_lower.hash_code end&lt;br /&gt;
        )&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;CAT&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar style applies to &amp;lt;e&amp;gt;V_HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_HASH_SET&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_TABLE&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_TABLE&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_SET&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Sometimes you want to use an object as a key in a table,&lt;br /&gt;
but the content of the object can change, so you cannot derive a hash code (or order) from any of its attributes.&lt;br /&gt;
EiffelBase2 provides a utility class &amp;lt;e&amp;gt;V_REFERENCE_HASHABLE&amp;lt;/e&amp;gt;,&lt;br /&gt;
which derives a hash code from the object's identity rather than its content.&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
class &lt;br /&gt;
    CAR&lt;br /&gt;
inherit &lt;br /&gt;
    V_REFERENCE_HASHABLE&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    color: COLOR&lt;br /&gt;
&lt;br /&gt;
    location: POINT&lt;br /&gt;
&lt;br /&gt;
feature -- Modification&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class GUI_APPLICATION&lt;br /&gt;
&lt;br /&gt;
feature&lt;br /&gt;
    cars: V_HASH_TABLE [CAR, CAR_VIEW]&lt;br /&gt;
            -- Cars in the city and their graphical views.&lt;br /&gt;
&lt;br /&gt;
    escape_police (c: CAR)&lt;br /&gt;
            -- Drive `c' away, repaint it and update its view.&lt;br /&gt;
        require&lt;br /&gt;
            car_in_city: cars.has_key (c)&lt;br /&gt;
        do&lt;br /&gt;
            c.move (100, 100) -- change location&lt;br /&gt;
            c.repaint (white) -- change color&lt;br /&gt;
            cars [c].update -- ... but still can be used to access its view&lt;br /&gt;
        end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Stream piping===&lt;br /&gt;
&lt;br /&gt;
Iterators in EiffelBase2 are a special case of streams. Sometimes you can avoid writing a loop by piping an input stream into an output stream, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        array: V_ARRAY [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create array.make (1, 10)&lt;br /&gt;
        -- Fill array with random integers:&lt;br /&gt;
        array.new_cursor.pipe (create {V_RANDOM})&lt;br /&gt;
        -- Fill array with values parsed from a string:&lt;br /&gt;
        array.new_cursor.pipe (create {V_STRING_INPUT [INTEGER]}.make (&amp;quot;1 2 3 4 5 6 7 8 9 10&amp;quot;, agent {STRING}.to_integer))&lt;br /&gt;
        -- Print array elements into standard output:&lt;br /&gt;
        (create {V_STANDARD_OUTPUT}).pipe (array.new_cursor)&lt;br /&gt;
        -- Prints &amp;quot;1 2 3 4 5 6 7 8 9 10 &amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence of elements is a model for a stack or a queue. &lt;br /&gt;
A triple consisting of a reference to the target container, the sequence of elements and an integer is a model for an iterator.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: target, sequence, index&lt;br /&gt;
&lt;br /&gt;
class V_LIST_ITERATOR [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
&lt;br /&gt;
    target: V_LIST&lt;br /&gt;
            -- List to iterate over.&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Current position.&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of elements in `target'.&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;V_LIST_ITERATOR&amp;lt;/e&amp;gt; consisting of tree components: &lt;br /&gt;
a reference (to &amp;lt;e&amp;gt;V_LIST&amp;lt;/e&amp;gt;), a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. &lt;br /&gt;
As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); &lt;br /&gt;
regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;target&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). &lt;br /&gt;
We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
Those annotations can be used by tools to check, if a specification-only feature accidentally got called from non-specification code,&lt;br /&gt;
and to remove such features from the code before compiling it.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of regular features in their terms. &lt;br /&gt;
For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. &lt;br /&gt;
For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments.&lt;br /&gt;
We also supply them with &amp;lt;e&amp;gt;modify&amp;lt;/e&amp;gt; clauses that list all the model queries whose values are allowed to be changed by the command.&lt;br /&gt;
These clauses can be used by tools to generate additional postconditions &amp;lt;e&amp;gt;m = old m&amp;lt;/e&amp;gt; &lt;br /&gt;
for each model query &amp;lt;e&amp;gt;m&amp;lt;/e&amp;gt; of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and other arguments that is not mentioned in the &amp;lt;e&amp;gt;modify&amp;lt;/e&amp;gt; clause.&lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: &lt;br /&gt;
it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;V_LIST_ITERATOR&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: target, sequence, index&lt;br /&gt;
&lt;br /&gt;
class V_LIST_ITERATOR [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position.&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is current position off scope?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Extension&lt;br /&gt;
&lt;br /&gt;
    extend_right (v: G)&lt;br /&gt;
            -- Insert `v' to the right of current position.&lt;br /&gt;
            -- Do not move cursor.&lt;br /&gt;
        note&lt;br /&gt;
            modify: sequence&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
	deferred&lt;br /&gt;
	ensure&lt;br /&gt;
	    sequence_effect: sequence |=| old (sequence.front (index) &amp;amp; v + sequence.tail (index + 1))&lt;br /&gt;
	end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, look at &amp;lt;e&amp;gt;V_SET&amp;lt;/e&amp;gt;, which inherits directly from &amp;lt;e&amp;gt;V_CONTAINER&amp;lt;/e&amp;gt;:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class V_CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: set&lt;br /&gt;
class V_SET[G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain |=| set&lt;br /&gt;
    bag_definition: bag.is_constant (1)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;V_SET&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new model query &amp;lt;e&amp;gt;set&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is currently being developed as a project at ETH Zurich.&lt;br /&gt;
&lt;br /&gt;
It has been used in the following projects:&lt;br /&gt;
* Traffic 4: modeling public transportation in a city [https://bitbucket.org/nadiapolikarpova/traffic https://bitbucket.org/nadiapolikarpova/traffic]&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14512</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14512"/>
				<updated>2012-06-27T13:22:34Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Status and roadmap */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library, which has for many years played a central role in Eiffel development.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
The latest version of the EiffelBase2 source code is available from the repository: [https://bitbucket.org/nadiapolikarpova/eiffelbase2/ https://bitbucket.org/nadiapolikarpova/eiffelbase2/]&lt;br /&gt;
&lt;br /&gt;
The source code is divided into two clusters:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;structures&amp;lt;/e&amp;gt; - Data Structures, the core of EiffelBase2. The rest of current document is about this cluster.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;mml&amp;lt;/e&amp;gt; - Mathematical Model Library: a library of immutable classes used in ''model-based contracts'' (see below).&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Complete specifications. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
On the top level EiffelBase2 differentiates between ''containers'' and ''streams''. A container is a finite storage of values, while a stream provides linear access to a set of values. A stream is not necessarily bound to a container, e.g. &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; stream observes an infinite sequence of pseudo-random numbers. Streams that traverse containers are called ''iterators''.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies: containers and streams/iterators. &lt;br /&gt;
All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity.&lt;br /&gt;
&lt;br /&gt;
In the diagrams below asterisk and italics font indicates a &amp;lt;e&amp;gt;deferred&amp;lt;/e&amp;gt; class.&lt;br /&gt;
Lighter fill color indicates that the class provides an ''immutable'' interface to the data,&lt;br /&gt;
in other words, it is impossible to modify the content of the container using this interface.&lt;br /&gt;
 &lt;br /&gt;
[[Image:eb2_container.png|1000px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
[[Image:eb2_iterator.png|1000px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
==Usage examples==&lt;br /&gt;
&lt;br /&gt;
===Immutable interfaces===&lt;br /&gt;
With immutable interfaces you can give your clients read-only access to a container you store:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
class TRAM_LINE&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    &lt;br /&gt;
    stations: V_SEQUENCE [STATION]&lt;br /&gt;
            -- Stations on the line.&lt;br /&gt;
            -- (Clients can traverse the stations, but cannot replace them, remove or add new ones.)&lt;br /&gt;
        do&lt;br /&gt;
            Result := station_list&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
feature {NONE} -- Implementation&lt;br /&gt;
&lt;br /&gt;
    station_list: V_LIST [STATION]&lt;br /&gt;
            -- List of line stations.&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Iterators===&lt;br /&gt;
Here is how you can iterate through any container:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    do&lt;br /&gt;
        across&lt;br /&gt;
            container as i&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same thing using the explicit syntax:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        from&lt;br /&gt;
            i := container.new_cursor&lt;br /&gt;
        until&lt;br /&gt;
            i.after&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is some more advanced stuff you can do with lists:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (list: V_LIST [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_LIST_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Find the last 0 at or before position 5:&lt;br /&gt;
        list.at (5).search_back (0)&lt;br /&gt;
        -- Find the first positive element at or after position 5:&lt;br /&gt;
        i := list.at (5)&lt;br /&gt;
        i.satisfy_forth (agent (x: INTEGER): BOOLEAN do Result := x &amp;gt; 0 end)&lt;br /&gt;
        -- And insert a 0 after it:&lt;br /&gt;
        i.extend_right (0)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Sets and tables===&lt;br /&gt;
&lt;br /&gt;
Here is how you create and use a simple hash table (keys must inherit from HASHABLE):&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create table.with_object_equality&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;cat&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you need a custom hash function or equivalence relation on keys, you can use V_GENERAL_HASH_TABLE, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_GENERAL_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Create case-insensitive table:&lt;br /&gt;
        create table.make (&lt;br /&gt;
            agent {STRING}.is_case_insensitive_equal,&lt;br /&gt;
            agent (s: STRING): INTEGER do Result := s.as_lower.hash_code end&lt;br /&gt;
        )&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;CAT&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar style applies to &amp;lt;e&amp;gt;V_HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_HASH_SET&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_TABLE&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_TABLE&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_SET&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Sometimes you want to use an object as a key in a table,&lt;br /&gt;
but the content of the object can change, so you cannot derive a hash code (or order) from any of its attributes.&lt;br /&gt;
EiffelBase2 provides a utility class &amp;lt;e&amp;gt;V_REFERENCE_HASHABLE&amp;lt;/e&amp;gt;,&lt;br /&gt;
which derives a hash code from the object's identity rather than its content.&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
class &lt;br /&gt;
    CAR&lt;br /&gt;
inherit &lt;br /&gt;
    V_REFERENCE_HASHABLE&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    color: COLOR&lt;br /&gt;
&lt;br /&gt;
    location: POINT&lt;br /&gt;
&lt;br /&gt;
feature -- Modification&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class GUI_APPLICATION&lt;br /&gt;
&lt;br /&gt;
feature&lt;br /&gt;
    cars: V_HASH_TABLE [CAR, CAR_VIEW]&lt;br /&gt;
            -- Cars in the city and their graphical views.&lt;br /&gt;
&lt;br /&gt;
    escape_police (c: CAR)&lt;br /&gt;
            -- Drive `c' away, repaint it and update its view.&lt;br /&gt;
        require&lt;br /&gt;
            car_in_city: cars.has_key (c)&lt;br /&gt;
        do&lt;br /&gt;
            c.move (100, 100) -- change location&lt;br /&gt;
            c.repaint (white) -- change color&lt;br /&gt;
            cars [c].update -- ... but still can be used to access its view&lt;br /&gt;
        end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Stream piping===&lt;br /&gt;
&lt;br /&gt;
Iterators in EiffelBase2 are a special case of streams. Sometimes you can avoid writing a loop by piping an input stream into an output stream, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        array: V_ARRAY [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create array.make (1, 10)&lt;br /&gt;
        -- Fill array with random integers:&lt;br /&gt;
        array.new_cursor.pipe (create {V_RANDOM})&lt;br /&gt;
        -- Fill array with values parsed from a string:&lt;br /&gt;
        array.new_cursor.pipe (create {V_STRING_INPUT [INTEGER]}.make (&amp;quot;1 2 3 4 5 6 7 8 9 10&amp;quot;, agent {STRING}.to_integer))&lt;br /&gt;
        -- Print array elements into standard output:&lt;br /&gt;
        (create {V_STANDARD_OUTPUT}).pipe (array.new_cursor)&lt;br /&gt;
        -- Prints &amp;quot;1 2 3 4 5 6 7 8 9 10 &amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence of elements is a model for a stack or a queue. &lt;br /&gt;
A triple consisting of a reference to the target container, the sequence of elements and an integer is a model for an iterator.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: target, sequence, index&lt;br /&gt;
&lt;br /&gt;
class V_LIST_ITERATOR [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
&lt;br /&gt;
    target: V_LIST&lt;br /&gt;
            -- List to iterate over.&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Current position.&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of elements in `target'.&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;V_LIST_ITERATOR&amp;lt;/e&amp;gt; consisting of tree components: &lt;br /&gt;
a reference (to &amp;lt;e&amp;gt;V_LIST&amp;lt;/e&amp;gt;), a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. &lt;br /&gt;
As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); &lt;br /&gt;
regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;target&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). &lt;br /&gt;
We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
Those annotations can be used by tools to check, if a specification-only feature accidentally got called from non-specification code,&lt;br /&gt;
and to remove such features from the code before compiling it.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of regular features in their terms. &lt;br /&gt;
For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. &lt;br /&gt;
For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments.&lt;br /&gt;
We also supply them with &amp;lt;e&amp;gt;modify&amp;lt;/e&amp;gt; clauses that list all the model queries whose values are allowed to be changed by the command.&lt;br /&gt;
These clauses can be used by tools to generate additional postconditions &amp;lt;e&amp;gt;m = old m&amp;lt;/e&amp;gt; &lt;br /&gt;
for each model query &amp;lt;e&amp;gt;m&amp;lt;/e&amp;gt; of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and other arguments that is not mentioned in the &amp;lt;e&amp;gt;modify&amp;lt;/e&amp;gt; clause.&lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: &lt;br /&gt;
it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;V_LIST_ITERATOR&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: target, sequence, index&lt;br /&gt;
&lt;br /&gt;
class V_LIST_ITERATOR [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position.&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is current position off scope?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Extension&lt;br /&gt;
&lt;br /&gt;
    extend_right (v: G)&lt;br /&gt;
            -- Insert `v' to the right of current position.&lt;br /&gt;
            -- Do not move cursor.&lt;br /&gt;
        note&lt;br /&gt;
            modify: sequence&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
	deferred&lt;br /&gt;
	ensure&lt;br /&gt;
	    sequence_effect: sequence |=| old (sequence.front (index) &amp;amp; v + sequence.tail (index + 1))&lt;br /&gt;
	end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, look at &amp;lt;e&amp;gt;V_SET&amp;lt;/e&amp;gt;, which inherits directly from &amp;lt;e&amp;gt;V_CONTAINER&amp;lt;/e&amp;gt;:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class V_CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: set&lt;br /&gt;
class V_SET[G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain |=| set&lt;br /&gt;
    bag_definition: bag.is_constant (1)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;V_SET&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new model query &amp;lt;e&amp;gt;set&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is currently being developed as a project at ETH Zurich.&lt;br /&gt;
&lt;br /&gt;
It has been used in the following projects:&lt;br /&gt;
* Traffic 4: modeling public transportation in a city [https://bitbucket.org/nadiapolikarpova/traffic https://bitbucket.org/nadiapolikarpova/traffic]&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14405</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14405"/>
				<updated>2012-04-11T14:19:29Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Sets and tables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library, which has for many years played a central role in Eiffel development.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
The latest version of the EiffelBase2 source code is available from the repository: [https://bitbucket.org/nadiapolikarpova/eiffelbase2/ https://bitbucket.org/nadiapolikarpova/eiffelbase2/]&lt;br /&gt;
&lt;br /&gt;
The source code is divided into two clusters:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;structures&amp;lt;/e&amp;gt; - Data Structures, the core of EiffelBase2. The rest of current document is about this cluster.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;mml&amp;lt;/e&amp;gt; - Mathematical Model Library: a library of immutable classes used in ''model-based contracts'' (see below).&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Complete specifications. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
On the top level EiffelBase2 differentiates between ''containers'' and ''streams''. A container is a finite storage of values, while a stream provides linear access to a set of values. A stream is not necessarily bound to a container, e.g. &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; stream observes an infinite sequence of pseudo-random numbers. Streams that traverse containers are called ''iterators''.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies: containers and streams/iterators. &lt;br /&gt;
All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity.&lt;br /&gt;
&lt;br /&gt;
In the diagrams below asterisk and italics font indicates a &amp;lt;e&amp;gt;deferred&amp;lt;/e&amp;gt; class.&lt;br /&gt;
Lighter fill color indicates that the class provides an ''immutable'' interface to the data,&lt;br /&gt;
in other words, it is impossible to modify the content of the container using this interface.&lt;br /&gt;
 &lt;br /&gt;
[[Image:eb2_container.png|1000px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
[[Image:eb2_iterator.png|1000px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
==Usage examples==&lt;br /&gt;
&lt;br /&gt;
===Immutable interfaces===&lt;br /&gt;
With immutable interfaces you can give your clients read-only access to a container you store:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
class TRAM_LINE&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    &lt;br /&gt;
    stations: V_SEQUENCE [STATION]&lt;br /&gt;
            -- Stations on the line.&lt;br /&gt;
            -- (Clients can traverse the stations, but cannot replace them, remove or add new ones.)&lt;br /&gt;
        do&lt;br /&gt;
            Result := station_list&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
feature {NONE} -- Implementation&lt;br /&gt;
&lt;br /&gt;
    station_list: V_LIST [STATION]&lt;br /&gt;
            -- List of line stations.&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Iterators===&lt;br /&gt;
Here is how you can iterate through any container:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    do&lt;br /&gt;
        across&lt;br /&gt;
            container as i&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same thing using the explicit syntax:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        from&lt;br /&gt;
            i := container.new_cursor&lt;br /&gt;
        until&lt;br /&gt;
            i.after&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is some more advanced stuff you can do with lists:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (list: V_LIST [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_LIST_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Find the last 0 at or before position 5:&lt;br /&gt;
        list.at (5).search_back (0)&lt;br /&gt;
        -- Find the first positive element at or after position 5:&lt;br /&gt;
        i := list.at (5)&lt;br /&gt;
        i.satisfy_forth (agent (x: INTEGER): BOOLEAN do Result := x &amp;gt; 0 end)&lt;br /&gt;
        -- And insert a 0 after it:&lt;br /&gt;
        i.extend_right (0)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Sets and tables===&lt;br /&gt;
&lt;br /&gt;
Here is how you create and use a simple hash table (keys must inherit from HASHABLE):&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create table.with_object_equality&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;cat&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you need a custom hash function or equivalence relation on keys, you can use V_GENERAL_HASH_TABLE, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_GENERAL_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Create case-insensitive table:&lt;br /&gt;
        create table.make (&lt;br /&gt;
            agent {STRING}.is_case_insensitive_equal,&lt;br /&gt;
            agent (s: STRING): INTEGER do Result := s.as_lower.hash_code end&lt;br /&gt;
        )&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;CAT&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar style applies to &amp;lt;e&amp;gt;V_HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_HASH_SET&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_TABLE&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_TABLE&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_SET&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Sometimes you want to use an object as a key in a table,&lt;br /&gt;
but the content of the object can change, so you cannot derive a hash code (or order) from any of its attributes.&lt;br /&gt;
EiffelBase2 provides a utility class &amp;lt;e&amp;gt;V_REFERENCE_HASHABLE&amp;lt;/e&amp;gt;,&lt;br /&gt;
which derives a hash code from the object's identity rather than its content.&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
class &lt;br /&gt;
    CAR&lt;br /&gt;
inherit &lt;br /&gt;
    V_REFERENCE_HASHABLE&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    color: COLOR&lt;br /&gt;
&lt;br /&gt;
    location: POINT&lt;br /&gt;
&lt;br /&gt;
feature -- Modification&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class GUI_APPLICATION&lt;br /&gt;
&lt;br /&gt;
feature&lt;br /&gt;
    cars: V_HASH_TABLE [CAR, CAR_VIEW]&lt;br /&gt;
            -- Cars in the city and their graphical views.&lt;br /&gt;
&lt;br /&gt;
    escape_police (c: CAR)&lt;br /&gt;
            -- Drive `c' away, repaint it and update its view.&lt;br /&gt;
        require&lt;br /&gt;
            car_in_city: cars.has_key (c)&lt;br /&gt;
        do&lt;br /&gt;
            c.move (100, 100) -- change location&lt;br /&gt;
            c.repaint (white) -- change color&lt;br /&gt;
            cars [c].update -- ... but still can be used to access its view&lt;br /&gt;
        end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Stream piping===&lt;br /&gt;
&lt;br /&gt;
Iterators in EiffelBase2 are a special case of streams. Sometimes you can avoid writing a loop by piping an input stream into an output stream, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        array: V_ARRAY [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create array.make (1, 10)&lt;br /&gt;
        -- Fill array with random integers:&lt;br /&gt;
        array.new_cursor.pipe (create {V_RANDOM})&lt;br /&gt;
        -- Fill array with values parsed from a string:&lt;br /&gt;
        array.new_cursor.pipe (create {V_STRING_INPUT [INTEGER]}.make (&amp;quot;1 2 3 4 5 6 7 8 9 10&amp;quot;, agent {STRING}.to_integer))&lt;br /&gt;
        -- Print array elements into standard output:&lt;br /&gt;
        (create {V_STANDARD_OUTPUT}).pipe (array.new_cursor)&lt;br /&gt;
        -- Prints &amp;quot;1 2 3 4 5 6 7 8 9 10 &amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence of elements is a model for a stack or a queue. &lt;br /&gt;
A triple consisting of a reference to the target container, the sequence of elements and an integer is a model for an iterator.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: target, sequence, index&lt;br /&gt;
&lt;br /&gt;
class V_LIST_ITERATOR [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
&lt;br /&gt;
    target: V_LIST&lt;br /&gt;
            -- List to iterate over.&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Current position.&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of elements in `target'.&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;V_LIST_ITERATOR&amp;lt;/e&amp;gt; consisting of tree components: &lt;br /&gt;
a reference (to &amp;lt;e&amp;gt;V_LIST&amp;lt;/e&amp;gt;), a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. &lt;br /&gt;
As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); &lt;br /&gt;
regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;target&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). &lt;br /&gt;
We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
Those annotations can be used by tools to check, if a specification-only feature accidentally got called from non-specification code,&lt;br /&gt;
and to remove such features from the code before compiling it.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of regular features in their terms. &lt;br /&gt;
For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. &lt;br /&gt;
For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments.&lt;br /&gt;
We also supply them with &amp;lt;e&amp;gt;modify&amp;lt;/e&amp;gt; clauses that list all the model queries whose values are allowed to be changed by the command.&lt;br /&gt;
These clauses can be used by tools to generate additional postconditions &amp;lt;e&amp;gt;m = old m&amp;lt;/e&amp;gt; &lt;br /&gt;
for each model query &amp;lt;e&amp;gt;m&amp;lt;/e&amp;gt; of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and other arguments that is not mentioned in the &amp;lt;e&amp;gt;modify&amp;lt;/e&amp;gt; clause.&lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: &lt;br /&gt;
it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;V_LIST_ITERATOR&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: target, sequence, index&lt;br /&gt;
&lt;br /&gt;
class V_LIST_ITERATOR [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position.&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is current position off scope?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Extension&lt;br /&gt;
&lt;br /&gt;
    extend_right (v: G)&lt;br /&gt;
            -- Insert `v' to the right of current position.&lt;br /&gt;
            -- Do not move cursor.&lt;br /&gt;
        note&lt;br /&gt;
            modify: sequence&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
	deferred&lt;br /&gt;
	ensure&lt;br /&gt;
	    sequence_effect: sequence |=| old (sequence.front (index) &amp;amp; v + sequence.tail (index + 1))&lt;br /&gt;
	end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, look at &amp;lt;e&amp;gt;V_SET&amp;lt;/e&amp;gt;, which inherits directly from &amp;lt;e&amp;gt;V_CONTAINER&amp;lt;/e&amp;gt;:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class V_CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: set&lt;br /&gt;
class V_SET[G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain |=| set&lt;br /&gt;
    bag_definition: bag.is_constant (1)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;V_SET&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new model query &amp;lt;e&amp;gt;set&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is currently being developed as a project at ETH Zurich.&lt;br /&gt;
&lt;br /&gt;
It has been used in the following projects:&lt;br /&gt;
* Traffic 4: modeling public transportation in a city [http://traffic.origo.ethz.ch/ http://traffic.origo.ethz.ch/]&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14404</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14404"/>
				<updated>2012-04-11T14:18:59Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Sets and tables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library, which has for many years played a central role in Eiffel development.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
The latest version of the EiffelBase2 source code is available from the repository: [https://bitbucket.org/nadiapolikarpova/eiffelbase2/ https://bitbucket.org/nadiapolikarpova/eiffelbase2/]&lt;br /&gt;
&lt;br /&gt;
The source code is divided into two clusters:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;structures&amp;lt;/e&amp;gt; - Data Structures, the core of EiffelBase2. The rest of current document is about this cluster.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;mml&amp;lt;/e&amp;gt; - Mathematical Model Library: a library of immutable classes used in ''model-based contracts'' (see below).&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Complete specifications. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
On the top level EiffelBase2 differentiates between ''containers'' and ''streams''. A container is a finite storage of values, while a stream provides linear access to a set of values. A stream is not necessarily bound to a container, e.g. &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; stream observes an infinite sequence of pseudo-random numbers. Streams that traverse containers are called ''iterators''.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies: containers and streams/iterators. &lt;br /&gt;
All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity.&lt;br /&gt;
&lt;br /&gt;
In the diagrams below asterisk and italics font indicates a &amp;lt;e&amp;gt;deferred&amp;lt;/e&amp;gt; class.&lt;br /&gt;
Lighter fill color indicates that the class provides an ''immutable'' interface to the data,&lt;br /&gt;
in other words, it is impossible to modify the content of the container using this interface.&lt;br /&gt;
 &lt;br /&gt;
[[Image:eb2_container.png|1000px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
[[Image:eb2_iterator.png|1000px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
==Usage examples==&lt;br /&gt;
&lt;br /&gt;
===Immutable interfaces===&lt;br /&gt;
With immutable interfaces you can give your clients read-only access to a container you store:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
class TRAM_LINE&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    &lt;br /&gt;
    stations: V_SEQUENCE [STATION]&lt;br /&gt;
            -- Stations on the line.&lt;br /&gt;
            -- (Clients can traverse the stations, but cannot replace them, remove or add new ones.)&lt;br /&gt;
        do&lt;br /&gt;
            Result := station_list&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
feature {NONE} -- Implementation&lt;br /&gt;
&lt;br /&gt;
    station_list: V_LIST [STATION]&lt;br /&gt;
            -- List of line stations.&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Iterators===&lt;br /&gt;
Here is how you can iterate through any container:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    do&lt;br /&gt;
        across&lt;br /&gt;
            container as i&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same thing using the explicit syntax:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        from&lt;br /&gt;
            i := container.new_cursor&lt;br /&gt;
        until&lt;br /&gt;
            i.after&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is some more advanced stuff you can do with lists:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (list: V_LIST [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_LIST_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Find the last 0 at or before position 5:&lt;br /&gt;
        list.at (5).search_back (0)&lt;br /&gt;
        -- Find the first positive element at or after position 5:&lt;br /&gt;
        i := list.at (5)&lt;br /&gt;
        i.satisfy_forth (agent (x: INTEGER): BOOLEAN do Result := x &amp;gt; 0 end)&lt;br /&gt;
        -- And insert a 0 after it:&lt;br /&gt;
        i.extend_right (0)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Sets and tables===&lt;br /&gt;
&lt;br /&gt;
Here is how you create and use a simple hash table (keys must inherit from HASHABLE):&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create table.with_object_equality&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;cat&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you need a custom hash function or equivalence relation on keys, you can use V_GENERAL_HASH_TABLE, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_GENERAL_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Create case-insensitive table:&lt;br /&gt;
        create table.make (&lt;br /&gt;
            agent {STRING}.is_case_insensitive_equal,&lt;br /&gt;
            agent (s: STRING): INTEGER do Result := s.as_lower.hash_code end&lt;br /&gt;
        )&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;CAT&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar style applies to &amp;lt;e&amp;gt;V_HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_HASH_SET&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_TABLE&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_TABLE&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_SET&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Sometimes you want to use an object as a key in a table,&lt;br /&gt;
but the content of the object can change, so you cannot derive a hash code (or order) from any of its attributes.&lt;br /&gt;
EiffelBase2 provides a utility class &amp;lt;e&amp;gt;V_REFERENCE_HASHABLE&amp;lt;/e&amp;gt;,&lt;br /&gt;
which derives a hash code from the object's identity rather than its content.&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
class &lt;br /&gt;
    CAR&lt;br /&gt;
inherit &lt;br /&gt;
    V_REFERENCE_HASHABLE&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    color: COLOR&lt;br /&gt;
&lt;br /&gt;
    location: POINT&lt;br /&gt;
&lt;br /&gt;
feature -- Modification&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class GUI_APPLICATION&lt;br /&gt;
&lt;br /&gt;
feature&lt;br /&gt;
    cars: V_HASH_TABLE [CAR, CAR_VIEW]&lt;br /&gt;
            -- Cars in the city and their graphical views.&lt;br /&gt;
&lt;br /&gt;
    escape_police (c: CAR)&lt;br /&gt;
            -- Drive `c' away, repaint it and update its view.&lt;br /&gt;
        require&lt;br /&gt;
            car_on_map: cars.has_key (c)&lt;br /&gt;
        do&lt;br /&gt;
            c.move (100, 100) -- change location&lt;br /&gt;
            c.repaint (white) -- change color&lt;br /&gt;
            cars [c].update -- ... but still can be used to access its view&lt;br /&gt;
        end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Stream piping===&lt;br /&gt;
&lt;br /&gt;
Iterators in EiffelBase2 are a special case of streams. Sometimes you can avoid writing a loop by piping an input stream into an output stream, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        array: V_ARRAY [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create array.make (1, 10)&lt;br /&gt;
        -- Fill array with random integers:&lt;br /&gt;
        array.new_cursor.pipe (create {V_RANDOM})&lt;br /&gt;
        -- Fill array with values parsed from a string:&lt;br /&gt;
        array.new_cursor.pipe (create {V_STRING_INPUT [INTEGER]}.make (&amp;quot;1 2 3 4 5 6 7 8 9 10&amp;quot;, agent {STRING}.to_integer))&lt;br /&gt;
        -- Print array elements into standard output:&lt;br /&gt;
        (create {V_STANDARD_OUTPUT}).pipe (array.new_cursor)&lt;br /&gt;
        -- Prints &amp;quot;1 2 3 4 5 6 7 8 9 10 &amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence of elements is a model for a stack or a queue. &lt;br /&gt;
A triple consisting of a reference to the target container, the sequence of elements and an integer is a model for an iterator.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: target, sequence, index&lt;br /&gt;
&lt;br /&gt;
class V_LIST_ITERATOR [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
&lt;br /&gt;
    target: V_LIST&lt;br /&gt;
            -- List to iterate over.&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Current position.&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of elements in `target'.&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;V_LIST_ITERATOR&amp;lt;/e&amp;gt; consisting of tree components: &lt;br /&gt;
a reference (to &amp;lt;e&amp;gt;V_LIST&amp;lt;/e&amp;gt;), a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. &lt;br /&gt;
As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); &lt;br /&gt;
regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;target&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). &lt;br /&gt;
We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
Those annotations can be used by tools to check, if a specification-only feature accidentally got called from non-specification code,&lt;br /&gt;
and to remove such features from the code before compiling it.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of regular features in their terms. &lt;br /&gt;
For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. &lt;br /&gt;
For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments.&lt;br /&gt;
We also supply them with &amp;lt;e&amp;gt;modify&amp;lt;/e&amp;gt; clauses that list all the model queries whose values are allowed to be changed by the command.&lt;br /&gt;
These clauses can be used by tools to generate additional postconditions &amp;lt;e&amp;gt;m = old m&amp;lt;/e&amp;gt; &lt;br /&gt;
for each model query &amp;lt;e&amp;gt;m&amp;lt;/e&amp;gt; of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and other arguments that is not mentioned in the &amp;lt;e&amp;gt;modify&amp;lt;/e&amp;gt; clause.&lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: &lt;br /&gt;
it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;V_LIST_ITERATOR&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: target, sequence, index&lt;br /&gt;
&lt;br /&gt;
class V_LIST_ITERATOR [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position.&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is current position off scope?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Extension&lt;br /&gt;
&lt;br /&gt;
    extend_right (v: G)&lt;br /&gt;
            -- Insert `v' to the right of current position.&lt;br /&gt;
            -- Do not move cursor.&lt;br /&gt;
        note&lt;br /&gt;
            modify: sequence&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
	deferred&lt;br /&gt;
	ensure&lt;br /&gt;
	    sequence_effect: sequence |=| old (sequence.front (index) &amp;amp; v + sequence.tail (index + 1))&lt;br /&gt;
	end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, look at &amp;lt;e&amp;gt;V_SET&amp;lt;/e&amp;gt;, which inherits directly from &amp;lt;e&amp;gt;V_CONTAINER&amp;lt;/e&amp;gt;:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class V_CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: set&lt;br /&gt;
class V_SET[G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain |=| set&lt;br /&gt;
    bag_definition: bag.is_constant (1)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;V_SET&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new model query &amp;lt;e&amp;gt;set&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is currently being developed as a project at ETH Zurich.&lt;br /&gt;
&lt;br /&gt;
It has been used in the following projects:&lt;br /&gt;
* Traffic 4: modeling public transportation in a city [http://traffic.origo.ethz.ch/ http://traffic.origo.ethz.ch/]&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14403</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14403"/>
				<updated>2012-04-11T14:16:49Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Sets and tables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library, which has for many years played a central role in Eiffel development.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
The latest version of the EiffelBase2 source code is available from the repository: [https://bitbucket.org/nadiapolikarpova/eiffelbase2/ https://bitbucket.org/nadiapolikarpova/eiffelbase2/]&lt;br /&gt;
&lt;br /&gt;
The source code is divided into two clusters:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;structures&amp;lt;/e&amp;gt; - Data Structures, the core of EiffelBase2. The rest of current document is about this cluster.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;mml&amp;lt;/e&amp;gt; - Mathematical Model Library: a library of immutable classes used in ''model-based contracts'' (see below).&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Complete specifications. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
On the top level EiffelBase2 differentiates between ''containers'' and ''streams''. A container is a finite storage of values, while a stream provides linear access to a set of values. A stream is not necessarily bound to a container, e.g. &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; stream observes an infinite sequence of pseudo-random numbers. Streams that traverse containers are called ''iterators''.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies: containers and streams/iterators. &lt;br /&gt;
All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity.&lt;br /&gt;
&lt;br /&gt;
In the diagrams below asterisk and italics font indicates a &amp;lt;e&amp;gt;deferred&amp;lt;/e&amp;gt; class.&lt;br /&gt;
Lighter fill color indicates that the class provides an ''immutable'' interface to the data,&lt;br /&gt;
in other words, it is impossible to modify the content of the container using this interface.&lt;br /&gt;
 &lt;br /&gt;
[[Image:eb2_container.png|1000px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
[[Image:eb2_iterator.png|1000px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
==Usage examples==&lt;br /&gt;
&lt;br /&gt;
===Immutable interfaces===&lt;br /&gt;
With immutable interfaces you can give your clients read-only access to a container you store:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
class TRAM_LINE&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    &lt;br /&gt;
    stations: V_SEQUENCE [STATION]&lt;br /&gt;
            -- Stations on the line.&lt;br /&gt;
            -- (Clients can traverse the stations, but cannot replace them, remove or add new ones.)&lt;br /&gt;
        do&lt;br /&gt;
            Result := station_list&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
feature {NONE} -- Implementation&lt;br /&gt;
&lt;br /&gt;
    station_list: V_LIST [STATION]&lt;br /&gt;
            -- List of line stations.&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Iterators===&lt;br /&gt;
Here is how you can iterate through any container:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    do&lt;br /&gt;
        across&lt;br /&gt;
            container as i&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same thing using the explicit syntax:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        from&lt;br /&gt;
            i := container.new_cursor&lt;br /&gt;
        until&lt;br /&gt;
            i.after&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is some more advanced stuff you can do with lists:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (list: V_LIST [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_LIST_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Find the last 0 at or before position 5:&lt;br /&gt;
        list.at (5).search_back (0)&lt;br /&gt;
        -- Find the first positive element at or after position 5:&lt;br /&gt;
        i := list.at (5)&lt;br /&gt;
        i.satisfy_forth (agent (x: INTEGER): BOOLEAN do Result := x &amp;gt; 0 end)&lt;br /&gt;
        -- And insert a 0 after it:&lt;br /&gt;
        i.extend_right (0)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Sets and tables===&lt;br /&gt;
&lt;br /&gt;
Here is how you create and use a simple hash table (keys must inherit from HASHABLE):&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create table.with_object_equality&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;cat&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you need a custom hash function or equivalence relation on keys, you can use V_GENERAL_HASH_TABLE, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_GENERAL_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Create case-insensitive table:&lt;br /&gt;
        create table.make (&lt;br /&gt;
            agent {STRING}.is_case_insensitive_equal,&lt;br /&gt;
            agent (s: STRING): INTEGER do Result := s.as_lower.hash_code end&lt;br /&gt;
        )&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;CAT&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar style applies to &amp;lt;e&amp;gt;V_HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_HASH_SET&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_TABLE&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_TABLE&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_SET&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Sometimes you want to use an object as a key in a table,&lt;br /&gt;
but the content of the object can change, so you cannot derive a hash code (or order) from any of its attributes.&lt;br /&gt;
EiffelBase2 provides a utility class &amp;lt;e&amp;gt;V_REFERENCE_HASHABLE&amp;lt;/e&amp;gt;,&lt;br /&gt;
which derives a hash code from the object's identity rather than its content.&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
class &lt;br /&gt;
    CAR&lt;br /&gt;
inherit &lt;br /&gt;
    V_REFERENCE_HASHABLE&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    color: COLOR&lt;br /&gt;
&lt;br /&gt;
    location: POINT&lt;br /&gt;
&lt;br /&gt;
feature -- Modification&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class GUI_APPLICATION&lt;br /&gt;
&lt;br /&gt;
feature&lt;br /&gt;
    cars: V_HASH_TABLE [CAR, CAR_VIEW]&lt;br /&gt;
&lt;br /&gt;
    escape_police (c: CAR)&lt;br /&gt;
        require&lt;br /&gt;
            car_on_map: cars.has_key (c)&lt;br /&gt;
        do&lt;br /&gt;
            c.move (100, 100) -- change location&lt;br /&gt;
            c.repaint (white) -- change color&lt;br /&gt;
            cars [c].update -- ... but still can be used to access its view&lt;br /&gt;
        end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Stream piping===&lt;br /&gt;
&lt;br /&gt;
Iterators in EiffelBase2 are a special case of streams. Sometimes you can avoid writing a loop by piping an input stream into an output stream, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        array: V_ARRAY [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create array.make (1, 10)&lt;br /&gt;
        -- Fill array with random integers:&lt;br /&gt;
        array.new_cursor.pipe (create {V_RANDOM})&lt;br /&gt;
        -- Fill array with values parsed from a string:&lt;br /&gt;
        array.new_cursor.pipe (create {V_STRING_INPUT [INTEGER]}.make (&amp;quot;1 2 3 4 5 6 7 8 9 10&amp;quot;, agent {STRING}.to_integer))&lt;br /&gt;
        -- Print array elements into standard output:&lt;br /&gt;
        (create {V_STANDARD_OUTPUT}).pipe (array.new_cursor)&lt;br /&gt;
        -- Prints &amp;quot;1 2 3 4 5 6 7 8 9 10 &amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence of elements is a model for a stack or a queue. &lt;br /&gt;
A triple consisting of a reference to the target container, the sequence of elements and an integer is a model for an iterator.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: target, sequence, index&lt;br /&gt;
&lt;br /&gt;
class V_LIST_ITERATOR [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
&lt;br /&gt;
    target: V_LIST&lt;br /&gt;
            -- List to iterate over.&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Current position.&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of elements in `target'.&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;V_LIST_ITERATOR&amp;lt;/e&amp;gt; consisting of tree components: &lt;br /&gt;
a reference (to &amp;lt;e&amp;gt;V_LIST&amp;lt;/e&amp;gt;), a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. &lt;br /&gt;
As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); &lt;br /&gt;
regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;target&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). &lt;br /&gt;
We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
Those annotations can be used by tools to check, if a specification-only feature accidentally got called from non-specification code,&lt;br /&gt;
and to remove such features from the code before compiling it.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of regular features in their terms. &lt;br /&gt;
For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. &lt;br /&gt;
For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments.&lt;br /&gt;
We also supply them with &amp;lt;e&amp;gt;modify&amp;lt;/e&amp;gt; clauses that list all the model queries whose values are allowed to be changed by the command.&lt;br /&gt;
These clauses can be used by tools to generate additional postconditions &amp;lt;e&amp;gt;m = old m&amp;lt;/e&amp;gt; &lt;br /&gt;
for each model query &amp;lt;e&amp;gt;m&amp;lt;/e&amp;gt; of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and other arguments that is not mentioned in the &amp;lt;e&amp;gt;modify&amp;lt;/e&amp;gt; clause.&lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: &lt;br /&gt;
it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;V_LIST_ITERATOR&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: target, sequence, index&lt;br /&gt;
&lt;br /&gt;
class V_LIST_ITERATOR [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position.&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is current position off scope?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Extension&lt;br /&gt;
&lt;br /&gt;
    extend_right (v: G)&lt;br /&gt;
            -- Insert `v' to the right of current position.&lt;br /&gt;
            -- Do not move cursor.&lt;br /&gt;
        note&lt;br /&gt;
            modify: sequence&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
	deferred&lt;br /&gt;
	ensure&lt;br /&gt;
	    sequence_effect: sequence |=| old (sequence.front (index) &amp;amp; v + sequence.tail (index + 1))&lt;br /&gt;
	end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, look at &amp;lt;e&amp;gt;V_SET&amp;lt;/e&amp;gt;, which inherits directly from &amp;lt;e&amp;gt;V_CONTAINER&amp;lt;/e&amp;gt;:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class V_CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: set&lt;br /&gt;
class V_SET[G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain |=| set&lt;br /&gt;
    bag_definition: bag.is_constant (1)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;V_SET&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new model query &amp;lt;e&amp;gt;set&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is currently being developed as a project at ETH Zurich.&lt;br /&gt;
&lt;br /&gt;
It has been used in the following projects:&lt;br /&gt;
* Traffic 4: modeling public transportation in a city [http://traffic.origo.ethz.ch/ http://traffic.origo.ethz.ch/]&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14402</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14402"/>
				<updated>2012-04-11T14:14:25Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Sets and tables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library, which has for many years played a central role in Eiffel development.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
The latest version of the EiffelBase2 source code is available from the repository: [https://bitbucket.org/nadiapolikarpova/eiffelbase2/ https://bitbucket.org/nadiapolikarpova/eiffelbase2/]&lt;br /&gt;
&lt;br /&gt;
The source code is divided into two clusters:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;structures&amp;lt;/e&amp;gt; - Data Structures, the core of EiffelBase2. The rest of current document is about this cluster.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;mml&amp;lt;/e&amp;gt; - Mathematical Model Library: a library of immutable classes used in ''model-based contracts'' (see below).&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Complete specifications. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
On the top level EiffelBase2 differentiates between ''containers'' and ''streams''. A container is a finite storage of values, while a stream provides linear access to a set of values. A stream is not necessarily bound to a container, e.g. &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; stream observes an infinite sequence of pseudo-random numbers. Streams that traverse containers are called ''iterators''.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies: containers and streams/iterators. &lt;br /&gt;
All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity.&lt;br /&gt;
&lt;br /&gt;
In the diagrams below asterisk and italics font indicates a &amp;lt;e&amp;gt;deferred&amp;lt;/e&amp;gt; class.&lt;br /&gt;
Lighter fill color indicates that the class provides an ''immutable'' interface to the data,&lt;br /&gt;
in other words, it is impossible to modify the content of the container using this interface.&lt;br /&gt;
 &lt;br /&gt;
[[Image:eb2_container.png|1000px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
[[Image:eb2_iterator.png|1000px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
==Usage examples==&lt;br /&gt;
&lt;br /&gt;
===Immutable interfaces===&lt;br /&gt;
With immutable interfaces you can give your clients read-only access to a container you store:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
class TRAM_LINE&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    &lt;br /&gt;
    stations: V_SEQUENCE [STATION]&lt;br /&gt;
            -- Stations on the line.&lt;br /&gt;
            -- (Clients can traverse the stations, but cannot replace them, remove or add new ones.)&lt;br /&gt;
        do&lt;br /&gt;
            Result := station_list&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
feature {NONE} -- Implementation&lt;br /&gt;
&lt;br /&gt;
    station_list: V_LIST [STATION]&lt;br /&gt;
            -- List of line stations.&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Iterators===&lt;br /&gt;
Here is how you can iterate through any container:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    do&lt;br /&gt;
        across&lt;br /&gt;
            container as i&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same thing using the explicit syntax:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        from&lt;br /&gt;
            i := container.new_cursor&lt;br /&gt;
        until&lt;br /&gt;
            i.after&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is some more advanced stuff you can do with lists:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (list: V_LIST [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_LIST_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Find the last 0 at or before position 5:&lt;br /&gt;
        list.at (5).search_back (0)&lt;br /&gt;
        -- Find the first positive element at or after position 5:&lt;br /&gt;
        i := list.at (5)&lt;br /&gt;
        i.satisfy_forth (agent (x: INTEGER): BOOLEAN do Result := x &amp;gt; 0 end)&lt;br /&gt;
        -- And insert a 0 after it:&lt;br /&gt;
        i.extend_right (0)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Sets and tables===&lt;br /&gt;
&lt;br /&gt;
Here is how you create and use a simple hash table (keys must inherit from HASHABLE):&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create table.with_object_equality&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;cat&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you need a custom hash function or equivalence relation on keys, you can use V_GENERAL_HASH_TABLE, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_GENERAL_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Create case-insensitive table:&lt;br /&gt;
        create table.make (&lt;br /&gt;
            agent {STRING}.is_case_insensitive_equal,&lt;br /&gt;
            agent (s: STRING): INTEGER do Result := s.as_lower.hash_code end&lt;br /&gt;
        )&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;CAT&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar style applies to &amp;lt;e&amp;gt;V_HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_HASH_SET&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_TABLE&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_TABLE&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_SET&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Sometimes you want to use an object as a key in a table,&lt;br /&gt;
but the content of the object can change, so you cannot derive a hash code (or order) from any of its attributes.&lt;br /&gt;
EiffelBase2 provides a utility class &amp;lt;e&amp;gt;V_REFERENCE_HASHABLE&amp;lt;/e&amp;gt;,&lt;br /&gt;
which derives a hash code from the object's identity rather than its content.&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
class &lt;br /&gt;
    CAR&lt;br /&gt;
inherit &lt;br /&gt;
    V_REFERENCE_HASHABLE&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    color: COLOR&lt;br /&gt;
&lt;br /&gt;
    location: POINT&lt;br /&gt;
&lt;br /&gt;
feature -- Modification&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MAP&lt;br /&gt;
&lt;br /&gt;
feature&lt;br /&gt;
    cars: V_HASH_TABLE [CAR, CAR_VIEW]&lt;br /&gt;
&lt;br /&gt;
    escape_police (c: CAR)&lt;br /&gt;
        require&lt;br /&gt;
            car_on_map: cars.has_key (c)&lt;br /&gt;
        do&lt;br /&gt;
            c.move (100, 100) -- change location&lt;br /&gt;
            c.repaint (white) -- change color&lt;br /&gt;
            cars [c].update -- ... but still can be used to access its view&lt;br /&gt;
        end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Stream piping===&lt;br /&gt;
&lt;br /&gt;
Iterators in EiffelBase2 are a special case of streams. Sometimes you can avoid writing a loop by piping an input stream into an output stream, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        array: V_ARRAY [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create array.make (1, 10)&lt;br /&gt;
        -- Fill array with random integers:&lt;br /&gt;
        array.new_cursor.pipe (create {V_RANDOM})&lt;br /&gt;
        -- Fill array with values parsed from a string:&lt;br /&gt;
        array.new_cursor.pipe (create {V_STRING_INPUT [INTEGER]}.make (&amp;quot;1 2 3 4 5 6 7 8 9 10&amp;quot;, agent {STRING}.to_integer))&lt;br /&gt;
        -- Print array elements into standard output:&lt;br /&gt;
        (create {V_STANDARD_OUTPUT}).pipe (array.new_cursor)&lt;br /&gt;
        -- Prints &amp;quot;1 2 3 4 5 6 7 8 9 10 &amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence of elements is a model for a stack or a queue. &lt;br /&gt;
A triple consisting of a reference to the target container, the sequence of elements and an integer is a model for an iterator.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: target, sequence, index&lt;br /&gt;
&lt;br /&gt;
class V_LIST_ITERATOR [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
&lt;br /&gt;
    target: V_LIST&lt;br /&gt;
            -- List to iterate over.&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Current position.&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of elements in `target'.&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;V_LIST_ITERATOR&amp;lt;/e&amp;gt; consisting of tree components: &lt;br /&gt;
a reference (to &amp;lt;e&amp;gt;V_LIST&amp;lt;/e&amp;gt;), a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. &lt;br /&gt;
As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); &lt;br /&gt;
regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;target&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). &lt;br /&gt;
We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
Those annotations can be used by tools to check, if a specification-only feature accidentally got called from non-specification code,&lt;br /&gt;
and to remove such features from the code before compiling it.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of regular features in their terms. &lt;br /&gt;
For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. &lt;br /&gt;
For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments.&lt;br /&gt;
We also supply them with &amp;lt;e&amp;gt;modify&amp;lt;/e&amp;gt; clauses that list all the model queries whose values are allowed to be changed by the command.&lt;br /&gt;
These clauses can be used by tools to generate additional postconditions &amp;lt;e&amp;gt;m = old m&amp;lt;/e&amp;gt; &lt;br /&gt;
for each model query &amp;lt;e&amp;gt;m&amp;lt;/e&amp;gt; of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and other arguments that is not mentioned in the &amp;lt;e&amp;gt;modify&amp;lt;/e&amp;gt; clause.&lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: &lt;br /&gt;
it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;V_LIST_ITERATOR&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: target, sequence, index&lt;br /&gt;
&lt;br /&gt;
class V_LIST_ITERATOR [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position.&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is current position off scope?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Extension&lt;br /&gt;
&lt;br /&gt;
    extend_right (v: G)&lt;br /&gt;
            -- Insert `v' to the right of current position.&lt;br /&gt;
            -- Do not move cursor.&lt;br /&gt;
        note&lt;br /&gt;
            modify: sequence&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
	deferred&lt;br /&gt;
	ensure&lt;br /&gt;
	    sequence_effect: sequence |=| old (sequence.front (index) &amp;amp; v + sequence.tail (index + 1))&lt;br /&gt;
	end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, look at &amp;lt;e&amp;gt;V_SET&amp;lt;/e&amp;gt;, which inherits directly from &amp;lt;e&amp;gt;V_CONTAINER&amp;lt;/e&amp;gt;:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class V_CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: set&lt;br /&gt;
class V_SET[G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain |=| set&lt;br /&gt;
    bag_definition: bag.is_constant (1)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;V_SET&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new model query &amp;lt;e&amp;gt;set&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is currently being developed as a project at ETH Zurich.&lt;br /&gt;
&lt;br /&gt;
It has been used in the following projects:&lt;br /&gt;
* Traffic 4: modeling public transportation in a city [http://traffic.origo.ethz.ch/ http://traffic.origo.ethz.ch/]&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14401</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14401"/>
				<updated>2012-04-11T13:34:40Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Sets and tables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library, which has for many years played a central role in Eiffel development.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
The latest version of the EiffelBase2 source code is available from the repository: [https://bitbucket.org/nadiapolikarpova/eiffelbase2/ https://bitbucket.org/nadiapolikarpova/eiffelbase2/]&lt;br /&gt;
&lt;br /&gt;
The source code is divided into two clusters:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;structures&amp;lt;/e&amp;gt; - Data Structures, the core of EiffelBase2. The rest of current document is about this cluster.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;mml&amp;lt;/e&amp;gt; - Mathematical Model Library: a library of immutable classes used in ''model-based contracts'' (see below).&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Complete specifications. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
On the top level EiffelBase2 differentiates between ''containers'' and ''streams''. A container is a finite storage of values, while a stream provides linear access to a set of values. A stream is not necessarily bound to a container, e.g. &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; stream observes an infinite sequence of pseudo-random numbers. Streams that traverse containers are called ''iterators''.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies: containers and streams/iterators. &lt;br /&gt;
All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity.&lt;br /&gt;
&lt;br /&gt;
In the diagrams below asterisk and italics font indicates a &amp;lt;e&amp;gt;deferred&amp;lt;/e&amp;gt; class.&lt;br /&gt;
Lighter fill color indicates that the class provides an ''immutable'' interface to the data,&lt;br /&gt;
in other words, it is impossible to modify the content of the container using this interface.&lt;br /&gt;
 &lt;br /&gt;
[[Image:eb2_container.png|1000px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
[[Image:eb2_iterator.png|1000px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
==Usage examples==&lt;br /&gt;
&lt;br /&gt;
===Immutable interfaces===&lt;br /&gt;
With immutable interfaces you can give your clients read-only access to a container you store:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
class TRAM_LINE&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    &lt;br /&gt;
    stations: V_SEQUENCE [STATION]&lt;br /&gt;
            -- Stations on the line.&lt;br /&gt;
            -- (Clients can traverse the stations, but cannot replace them, remove or add new ones.)&lt;br /&gt;
        do&lt;br /&gt;
            Result := station_list&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
feature {NONE} -- Implementation&lt;br /&gt;
&lt;br /&gt;
    station_list: V_LIST [STATION]&lt;br /&gt;
            -- List of line stations.&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Iterators===&lt;br /&gt;
Here is how you can iterate through any container:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    do&lt;br /&gt;
        across&lt;br /&gt;
            container as i&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same thing using the explicit syntax:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        from&lt;br /&gt;
            i := container.new_cursor&lt;br /&gt;
        until&lt;br /&gt;
            i.after&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is some more advanced stuff you can do with lists:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (list: V_LIST [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_LIST_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Find the last 0 at or before position 5:&lt;br /&gt;
        list.at (5).search_back (0)&lt;br /&gt;
        -- Find the first positive element at or after position 5:&lt;br /&gt;
        i := list.at (5)&lt;br /&gt;
        i.satisfy_forth (agent (x: INTEGER): BOOLEAN do Result := x &amp;gt; 0 end)&lt;br /&gt;
        -- And insert a 0 after it:&lt;br /&gt;
        i.extend_right (0)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Sets and tables===&lt;br /&gt;
&lt;br /&gt;
Here is how you create and use a simple hash table (keys must inherit from HASHABLE):&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create table.with_object_equality&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;cat&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you need a custom hash function or equivalence relation on keys, you can use V_GENERAL_HASH_TABLE, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_GENERAL_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Create case-insensitive table:&lt;br /&gt;
        create table.make (&lt;br /&gt;
            agent {STRING}.is_case_insensitive_equal,&lt;br /&gt;
            agent (s: STRING): INTEGER do Result := s.as_lower.hash_code end&lt;br /&gt;
        )&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;CAT&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar style applies to &amp;lt;e&amp;gt;V_HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_HASH_SET&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_TABLE&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_TABLE&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_SET&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Sometimes you want to use an object as a key in a table,&lt;br /&gt;
but the content of the object can change, so you cannot derive a hash code (or order) from any of its attributes.&lt;br /&gt;
EiffelBase2 provides a utility class &amp;lt;e&amp;gt;V_REFERNCE_HASHABLE&amp;lt;/e&amp;gt;,&lt;br /&gt;
which derives a hash code from the object's identity rather than its content.&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
class &lt;br /&gt;
    CAR&lt;br /&gt;
inherit &lt;br /&gt;
    V_REFERENCE_HASHABLE&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    color: COLOR&lt;br /&gt;
&lt;br /&gt;
    location: POINT&lt;br /&gt;
&lt;br /&gt;
feature -- Modification&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MAP&lt;br /&gt;
&lt;br /&gt;
feature&lt;br /&gt;
    cars: V_HASH_TABLE [CAR, CAR_VIEW]&lt;br /&gt;
&lt;br /&gt;
    escape_police (c: CAR)&lt;br /&gt;
        require&lt;br /&gt;
            car_on_map: cars.has_key (c)&lt;br /&gt;
        do&lt;br /&gt;
            c.move (100, 100) -- change location&lt;br /&gt;
            c.repaint (white) -- change color&lt;br /&gt;
            cars [c].update -- ... but still can be used to access its view&lt;br /&gt;
        end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Stream piping===&lt;br /&gt;
&lt;br /&gt;
Iterators in EiffelBase2 are a special case of streams. Sometimes you can avoid writing a loop by piping an input stream into an output stream, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        array: V_ARRAY [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create array.make (1, 10)&lt;br /&gt;
        -- Fill array with random integers:&lt;br /&gt;
        array.new_cursor.pipe (create {V_RANDOM})&lt;br /&gt;
        -- Fill array with values parsed from a string:&lt;br /&gt;
        array.new_cursor.pipe (create {V_STRING_INPUT [INTEGER]}.make (&amp;quot;1 2 3 4 5 6 7 8 9 10&amp;quot;, agent {STRING}.to_integer))&lt;br /&gt;
        -- Print array elements into standard output:&lt;br /&gt;
        (create {V_STANDARD_OUTPUT}).pipe (array.new_cursor)&lt;br /&gt;
        -- Prints &amp;quot;1 2 3 4 5 6 7 8 9 10 &amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence of elements is a model for a stack or a queue. &lt;br /&gt;
A triple consisting of a reference to the target container, the sequence of elements and an integer is a model for an iterator.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: target, sequence, index&lt;br /&gt;
&lt;br /&gt;
class V_LIST_ITERATOR [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
&lt;br /&gt;
    target: V_LIST&lt;br /&gt;
            -- List to iterate over.&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Current position.&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of elements in `target'.&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;V_LIST_ITERATOR&amp;lt;/e&amp;gt; consisting of tree components: &lt;br /&gt;
a reference (to &amp;lt;e&amp;gt;V_LIST&amp;lt;/e&amp;gt;), a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. &lt;br /&gt;
As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); &lt;br /&gt;
regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;target&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). &lt;br /&gt;
We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
Those annotations can be used by tools to check, if a specification-only feature accidentally got called from non-specification code,&lt;br /&gt;
and to remove such features from the code before compiling it.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of regular features in their terms. &lt;br /&gt;
For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. &lt;br /&gt;
For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments.&lt;br /&gt;
We also supply them with &amp;lt;e&amp;gt;modify&amp;lt;/e&amp;gt; clauses that list all the model queries whose values are allowed to be changed by the command.&lt;br /&gt;
These clauses can be used by tools to generate additional postconditions &amp;lt;e&amp;gt;m = old m&amp;lt;/e&amp;gt; &lt;br /&gt;
for each model query &amp;lt;e&amp;gt;m&amp;lt;/e&amp;gt; of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and other arguments that is not mentioned in the &amp;lt;e&amp;gt;modify&amp;lt;/e&amp;gt; clause.&lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: &lt;br /&gt;
it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;V_LIST_ITERATOR&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: target, sequence, index&lt;br /&gt;
&lt;br /&gt;
class V_LIST_ITERATOR [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position.&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is current position off scope?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Extension&lt;br /&gt;
&lt;br /&gt;
    extend_right (v: G)&lt;br /&gt;
            -- Insert `v' to the right of current position.&lt;br /&gt;
            -- Do not move cursor.&lt;br /&gt;
        note&lt;br /&gt;
            modify: sequence&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
	deferred&lt;br /&gt;
	ensure&lt;br /&gt;
	    sequence_effect: sequence |=| old (sequence.front (index) &amp;amp; v + sequence.tail (index + 1))&lt;br /&gt;
	end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, look at &amp;lt;e&amp;gt;V_SET&amp;lt;/e&amp;gt;, which inherits directly from &amp;lt;e&amp;gt;V_CONTAINER&amp;lt;/e&amp;gt;:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class V_CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: set&lt;br /&gt;
class V_SET[G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain |=| set&lt;br /&gt;
    bag_definition: bag.is_constant (1)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;V_SET&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new model query &amp;lt;e&amp;gt;set&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is currently being developed as a project at ETH Zurich.&lt;br /&gt;
&lt;br /&gt;
It has been used in the following projects:&lt;br /&gt;
* Traffic 4: modeling public transportation in a city [http://traffic.origo.ethz.ch/ http://traffic.origo.ethz.ch/]&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14385</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14385"/>
				<updated>2012-04-05T15:33:31Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Inheritance */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library, which has for many years played a central role in Eiffel development.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
The latest version of the EiffelBase2 source code is available from the repository: [https://bitbucket.org/nadiapolikarpova/eiffelbase2/ https://bitbucket.org/nadiapolikarpova/eiffelbase2/]&lt;br /&gt;
&lt;br /&gt;
The source code is divided into two clusters:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;structures&amp;lt;/e&amp;gt; - Data Structures, the core of EiffelBase2. The rest of current document is about this cluster.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;mml&amp;lt;/e&amp;gt; - Mathematical Model Library: a library of immutable classes used in ''model-based contracts'' (see below).&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Complete specifications. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
On the top level EiffelBase2 differentiates between ''containers'' and ''streams''. A container is a finite storage of values, while a stream provides linear access to a set of values. A stream is not necessarily bound to a container, e.g. &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; stream observes an infinite sequence of pseudo-random numbers. Streams that traverse containers are called ''iterators''.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies: containers and streams/iterators. &lt;br /&gt;
All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity.&lt;br /&gt;
&lt;br /&gt;
In the diagrams below asterisk and italics font indicates a &amp;lt;e&amp;gt;deferred&amp;lt;/e&amp;gt; class.&lt;br /&gt;
Lighter fill color indicates that the class provides an ''immutable'' interface to the data,&lt;br /&gt;
in other words, it is impossible to modify the content of the container using this interface.&lt;br /&gt;
 &lt;br /&gt;
[[Image:eb2_container.png|1000px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
[[Image:eb2_iterator.png|1000px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
==Usage examples==&lt;br /&gt;
&lt;br /&gt;
===Immutable interfaces===&lt;br /&gt;
With immutable interfaces you can give your clients read-only access to a container you store:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
class TRAM_LINE&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    &lt;br /&gt;
    stations: V_SEQUENCE [STATION]&lt;br /&gt;
            -- Stations on the line.&lt;br /&gt;
            -- (Clients can traverse the stations, but cannot replace them, remove or add new ones.)&lt;br /&gt;
        do&lt;br /&gt;
            Result := station_list&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
feature {NONE} -- Implementation&lt;br /&gt;
&lt;br /&gt;
    station_list: V_LIST [STATION]&lt;br /&gt;
            -- List of line stations.&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Iterators===&lt;br /&gt;
Here is how you can iterate through any container:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    do&lt;br /&gt;
        across&lt;br /&gt;
            container as i&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same thing using the explicit syntax:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        from&lt;br /&gt;
            i := container.new_cursor&lt;br /&gt;
        until&lt;br /&gt;
            i.after&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is some more advanced stuff you can do with lists:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (list: V_LIST [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_LIST_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Find the last 0 at or before position 5:&lt;br /&gt;
        list.at (5).search_back (0)&lt;br /&gt;
        -- Find the first positive element at or after position 5:&lt;br /&gt;
        i := list.at (5)&lt;br /&gt;
        i.satisfy_forth (agent (x: INTEGER): BOOLEAN do Result := x &amp;gt; 0 end)&lt;br /&gt;
        -- And insert a 0 after it:&lt;br /&gt;
        i.extend_right (0)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Sets and tables===&lt;br /&gt;
&lt;br /&gt;
Here is how you create and use a simple hash table (keys must inherit from HASHABLE):&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create table.with_object_equality&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;cat&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you need a custom hash function or equivalence relation on keys, you can use V_GENERAL_HASH_TABLE, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_GENERAL_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Create case-insensitive table:&lt;br /&gt;
        create table.make (&lt;br /&gt;
            agent {STRING}.is_case_insensitive_equal,&lt;br /&gt;
            agent (s: STRING): INTEGER do Result := s.as_lower.hash_code end&lt;br /&gt;
        )&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;CAT&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar style applies to &amp;lt;e&amp;gt;V_HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_HASH_SET&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_TABLE&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_TABLE&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_SET&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Stream piping===&lt;br /&gt;
&lt;br /&gt;
Iterators in EiffelBase2 are a special case of streams. Sometimes you can avoid writing a loop by piping an input stream into an output stream, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        array: V_ARRAY [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create array.make (1, 10)&lt;br /&gt;
        -- Fill array with random integers:&lt;br /&gt;
        array.new_cursor.pipe (create {V_RANDOM})&lt;br /&gt;
        -- Fill array with values parsed from a string:&lt;br /&gt;
        array.new_cursor.pipe (create {V_STRING_INPUT [INTEGER]}.make (&amp;quot;1 2 3 4 5 6 7 8 9 10&amp;quot;, agent {STRING}.to_integer))&lt;br /&gt;
        -- Print array elements into standard output:&lt;br /&gt;
        (create {V_STANDARD_OUTPUT}).pipe (array.new_cursor)&lt;br /&gt;
        -- Prints &amp;quot;1 2 3 4 5 6 7 8 9 10 &amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence of elements is a model for a stack or a queue. &lt;br /&gt;
A triple consisting of a reference to the target container, the sequence of elements and an integer is a model for an iterator.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: target, sequence, index&lt;br /&gt;
&lt;br /&gt;
class V_LIST_ITERATOR [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
&lt;br /&gt;
    target: V_LIST&lt;br /&gt;
            -- List to iterate over.&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Current position.&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of elements in `target'.&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;V_LIST_ITERATOR&amp;lt;/e&amp;gt; consisting of tree components: &lt;br /&gt;
a reference (to &amp;lt;e&amp;gt;V_LIST&amp;lt;/e&amp;gt;), a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. &lt;br /&gt;
As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); &lt;br /&gt;
regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;target&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). &lt;br /&gt;
We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
Those annotations can be used by tools to check, if a specification-only feature accidentally got called from non-specification code,&lt;br /&gt;
and to remove such features from the code before compiling it.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of regular features in their terms. &lt;br /&gt;
For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. &lt;br /&gt;
For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments.&lt;br /&gt;
We also supply them with &amp;lt;e&amp;gt;modify&amp;lt;/e&amp;gt; clauses that list all the model queries whose values are allowed to be changed by the command.&lt;br /&gt;
These clauses can be used by tools to generate additional postconditions &amp;lt;e&amp;gt;m = old m&amp;lt;/e&amp;gt; &lt;br /&gt;
for each model query &amp;lt;e&amp;gt;m&amp;lt;/e&amp;gt; of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and other arguments that is not mentioned in the &amp;lt;e&amp;gt;modify&amp;lt;/e&amp;gt; clause.&lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: &lt;br /&gt;
it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;V_LIST_ITERATOR&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: target, sequence, index&lt;br /&gt;
&lt;br /&gt;
class V_LIST_ITERATOR [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position.&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is current position off scope?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Extension&lt;br /&gt;
&lt;br /&gt;
    extend_right (v: G)&lt;br /&gt;
            -- Insert `v' to the right of current position.&lt;br /&gt;
            -- Do not move cursor.&lt;br /&gt;
        note&lt;br /&gt;
            modify: sequence&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
	deferred&lt;br /&gt;
	ensure&lt;br /&gt;
	    sequence_effect: sequence |=| old (sequence.front (index) &amp;amp; v + sequence.tail (index + 1))&lt;br /&gt;
	end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, look at &amp;lt;e&amp;gt;V_SET&amp;lt;/e&amp;gt;, which inherits directly from &amp;lt;e&amp;gt;V_CONTAINER&amp;lt;/e&amp;gt;:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class V_CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: set&lt;br /&gt;
class V_SET[G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain |=| set&lt;br /&gt;
    bag_definition: bag.is_constant (1)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;V_SET&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new model query &amp;lt;e&amp;gt;set&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is currently being developed as a project at ETH Zurich.&lt;br /&gt;
&lt;br /&gt;
It has been used in the following projects:&lt;br /&gt;
* Traffic 4: modeling public transportation in a city [http://traffic.origo.ethz.ch/ http://traffic.origo.ethz.ch/]&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14384</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14384"/>
				<updated>2012-04-05T15:29:03Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Status and roadmap */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library, which has for many years played a central role in Eiffel development.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
The latest version of the EiffelBase2 source code is available from the repository: [https://bitbucket.org/nadiapolikarpova/eiffelbase2/ https://bitbucket.org/nadiapolikarpova/eiffelbase2/]&lt;br /&gt;
&lt;br /&gt;
The source code is divided into two clusters:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;structures&amp;lt;/e&amp;gt; - Data Structures, the core of EiffelBase2. The rest of current document is about this cluster.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;mml&amp;lt;/e&amp;gt; - Mathematical Model Library: a library of immutable classes used in ''model-based contracts'' (see below).&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Complete specifications. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
On the top level EiffelBase2 differentiates between ''containers'' and ''streams''. A container is a finite storage of values, while a stream provides linear access to a set of values. A stream is not necessarily bound to a container, e.g. &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; stream observes an infinite sequence of pseudo-random numbers. Streams that traverse containers are called ''iterators''.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies: containers and streams/iterators. &lt;br /&gt;
All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity.&lt;br /&gt;
&lt;br /&gt;
In the diagrams below asterisk and italics font indicates a &amp;lt;e&amp;gt;deferred&amp;lt;/e&amp;gt; class.&lt;br /&gt;
Lighter fill color indicates that the class provides an ''immutable'' interface to the data,&lt;br /&gt;
in other words, it is impossible to modify the content of the container using this interface.&lt;br /&gt;
 &lt;br /&gt;
[[Image:eb2_container.png|1000px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
[[Image:eb2_iterator.png|1000px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
==Usage examples==&lt;br /&gt;
&lt;br /&gt;
===Immutable interfaces===&lt;br /&gt;
With immutable interfaces you can give your clients read-only access to a container you store:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
class TRAM_LINE&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    &lt;br /&gt;
    stations: V_SEQUENCE [STATION]&lt;br /&gt;
            -- Stations on the line.&lt;br /&gt;
            -- (Clients can traverse the stations, but cannot replace them, remove or add new ones.)&lt;br /&gt;
        do&lt;br /&gt;
            Result := station_list&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
feature {NONE} -- Implementation&lt;br /&gt;
&lt;br /&gt;
    station_list: V_LIST [STATION]&lt;br /&gt;
            -- List of line stations.&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Iterators===&lt;br /&gt;
Here is how you can iterate through any container:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    do&lt;br /&gt;
        across&lt;br /&gt;
            container as i&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same thing using the explicit syntax:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        from&lt;br /&gt;
            i := container.new_cursor&lt;br /&gt;
        until&lt;br /&gt;
            i.after&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is some more advanced stuff you can do with lists:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (list: V_LIST [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_LIST_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Find the last 0 at or before position 5:&lt;br /&gt;
        list.at (5).search_back (0)&lt;br /&gt;
        -- Find the first positive element at or after position 5:&lt;br /&gt;
        i := list.at (5)&lt;br /&gt;
        i.satisfy_forth (agent (x: INTEGER): BOOLEAN do Result := x &amp;gt; 0 end)&lt;br /&gt;
        -- And insert a 0 after it:&lt;br /&gt;
        i.extend_right (0)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Sets and tables===&lt;br /&gt;
&lt;br /&gt;
Here is how you create and use a simple hash table (keys must inherit from HASHABLE):&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create table.with_object_equality&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;cat&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you need a custom hash function or equivalence relation on keys, you can use V_GENERAL_HASH_TABLE, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_GENERAL_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Create case-insensitive table:&lt;br /&gt;
        create table.make (&lt;br /&gt;
            agent {STRING}.is_case_insensitive_equal,&lt;br /&gt;
            agent (s: STRING): INTEGER do Result := s.as_lower.hash_code end&lt;br /&gt;
        )&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;CAT&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar style applies to &amp;lt;e&amp;gt;V_HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_HASH_SET&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_TABLE&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_TABLE&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_SET&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Stream piping===&lt;br /&gt;
&lt;br /&gt;
Iterators in EiffelBase2 are a special case of streams. Sometimes you can avoid writing a loop by piping an input stream into an output stream, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        array: V_ARRAY [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create array.make (1, 10)&lt;br /&gt;
        -- Fill array with random integers:&lt;br /&gt;
        array.new_cursor.pipe (create {V_RANDOM})&lt;br /&gt;
        -- Fill array with values parsed from a string:&lt;br /&gt;
        array.new_cursor.pipe (create {V_STRING_INPUT [INTEGER]}.make (&amp;quot;1 2 3 4 5 6 7 8 9 10&amp;quot;, agent {STRING}.to_integer))&lt;br /&gt;
        -- Print array elements into standard output:&lt;br /&gt;
        (create {V_STANDARD_OUTPUT}).pipe (array.new_cursor)&lt;br /&gt;
        -- Prints &amp;quot;1 2 3 4 5 6 7 8 9 10 &amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence of elements is a model for a stack or a queue. &lt;br /&gt;
A triple consisting of a reference to the target container, the sequence of elements and an integer is a model for an iterator.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: target, sequence, index&lt;br /&gt;
&lt;br /&gt;
class V_LIST_ITERATOR [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
&lt;br /&gt;
    target: V_LIST&lt;br /&gt;
            -- List to iterate over.&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Current position.&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of elements in `target'.&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;V_LIST_ITERATOR&amp;lt;/e&amp;gt; consisting of tree components: &lt;br /&gt;
a reference (to &amp;lt;e&amp;gt;V_LIST&amp;lt;/e&amp;gt;), a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. &lt;br /&gt;
As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); &lt;br /&gt;
regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;target&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). &lt;br /&gt;
We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
Those annotations can be used by tools to check, if a specification-only feature accidentally got called from non-specification code,&lt;br /&gt;
and to remove such features from the code before compiling it.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of regular features in their terms. &lt;br /&gt;
For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. &lt;br /&gt;
For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments.&lt;br /&gt;
We also supply them with &amp;lt;e&amp;gt;modify&amp;lt;/e&amp;gt; clauses that list all the model queries whose values are allowed to be changed by the command.&lt;br /&gt;
These clauses can be used by tools to generate additional postconditions &amp;lt;e&amp;gt;m = old m&amp;lt;/e&amp;gt; &lt;br /&gt;
for each model query &amp;lt;e&amp;gt;m&amp;lt;/e&amp;gt; of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and other arguments that is not mentioned in the &amp;lt;e&amp;gt;modify&amp;lt;/e&amp;gt; clause.&lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: &lt;br /&gt;
it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;V_LIST_ITERATOR&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: target, sequence, index&lt;br /&gt;
&lt;br /&gt;
class V_LIST_ITERATOR [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position.&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is current position off scope?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Extension&lt;br /&gt;
&lt;br /&gt;
    extend_right (v: G)&lt;br /&gt;
            -- Insert `v' to the right of current position.&lt;br /&gt;
            -- Do not move cursor.&lt;br /&gt;
        note&lt;br /&gt;
            modify: sequence&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
	deferred&lt;br /&gt;
	ensure&lt;br /&gt;
	    sequence_effect: sequence |=| old (sequence.front (index) &amp;amp; v + sequence.tail (index + 1))&lt;br /&gt;
	end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, suppose that &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; inherits directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;, whose model is a bag:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain = sequence.range&lt;br /&gt;
    bag_definition: bag.domain.for all (agent (x: G): BOOLEAN&lt;br /&gt;
        do Result := bag [x] = sequence.occurrences (x) end)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new  model query &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is currently being developed as a project at ETH Zurich.&lt;br /&gt;
&lt;br /&gt;
It has been used in the following projects:&lt;br /&gt;
* Traffic 4: modeling public transportation in a city [http://traffic.origo.ethz.ch/ http://traffic.origo.ethz.ch/]&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14383</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14383"/>
				<updated>2012-04-05T15:27:38Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Models */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library, which has for many years played a central role in Eiffel development.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
The latest version of the EiffelBase2 source code is available from the repository: [https://bitbucket.org/nadiapolikarpova/eiffelbase2/ https://bitbucket.org/nadiapolikarpova/eiffelbase2/]&lt;br /&gt;
&lt;br /&gt;
The source code is divided into two clusters:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;structures&amp;lt;/e&amp;gt; - Data Structures, the core of EiffelBase2. The rest of current document is about this cluster.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;mml&amp;lt;/e&amp;gt; - Mathematical Model Library: a library of immutable classes used in ''model-based contracts'' (see below).&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Complete specifications. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
On the top level EiffelBase2 differentiates between ''containers'' and ''streams''. A container is a finite storage of values, while a stream provides linear access to a set of values. A stream is not necessarily bound to a container, e.g. &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; stream observes an infinite sequence of pseudo-random numbers. Streams that traverse containers are called ''iterators''.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies: containers and streams/iterators. &lt;br /&gt;
All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity.&lt;br /&gt;
&lt;br /&gt;
In the diagrams below asterisk and italics font indicates a &amp;lt;e&amp;gt;deferred&amp;lt;/e&amp;gt; class.&lt;br /&gt;
Lighter fill color indicates that the class provides an ''immutable'' interface to the data,&lt;br /&gt;
in other words, it is impossible to modify the content of the container using this interface.&lt;br /&gt;
 &lt;br /&gt;
[[Image:eb2_container.png|1000px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
[[Image:eb2_iterator.png|1000px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
==Usage examples==&lt;br /&gt;
&lt;br /&gt;
===Immutable interfaces===&lt;br /&gt;
With immutable interfaces you can give your clients read-only access to a container you store:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
class TRAM_LINE&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    &lt;br /&gt;
    stations: V_SEQUENCE [STATION]&lt;br /&gt;
            -- Stations on the line.&lt;br /&gt;
            -- (Clients can traverse the stations, but cannot replace them, remove or add new ones.)&lt;br /&gt;
        do&lt;br /&gt;
            Result := station_list&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
feature {NONE} -- Implementation&lt;br /&gt;
&lt;br /&gt;
    station_list: V_LIST [STATION]&lt;br /&gt;
            -- List of line stations.&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Iterators===&lt;br /&gt;
Here is how you can iterate through any container:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    do&lt;br /&gt;
        across&lt;br /&gt;
            container as i&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same thing using the explicit syntax:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        from&lt;br /&gt;
            i := container.new_cursor&lt;br /&gt;
        until&lt;br /&gt;
            i.after&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is some more advanced stuff you can do with lists:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (list: V_LIST [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_LIST_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Find the last 0 at or before position 5:&lt;br /&gt;
        list.at (5).search_back (0)&lt;br /&gt;
        -- Find the first positive element at or after position 5:&lt;br /&gt;
        i := list.at (5)&lt;br /&gt;
        i.satisfy_forth (agent (x: INTEGER): BOOLEAN do Result := x &amp;gt; 0 end)&lt;br /&gt;
        -- And insert a 0 after it:&lt;br /&gt;
        i.extend_right (0)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Sets and tables===&lt;br /&gt;
&lt;br /&gt;
Here is how you create and use a simple hash table (keys must inherit from HASHABLE):&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create table.with_object_equality&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;cat&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you need a custom hash function or equivalence relation on keys, you can use V_GENERAL_HASH_TABLE, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_GENERAL_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Create case-insensitive table:&lt;br /&gt;
        create table.make (&lt;br /&gt;
            agent {STRING}.is_case_insensitive_equal,&lt;br /&gt;
            agent (s: STRING): INTEGER do Result := s.as_lower.hash_code end&lt;br /&gt;
        )&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;CAT&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar style applies to &amp;lt;e&amp;gt;V_HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_HASH_SET&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_TABLE&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_TABLE&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_SET&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Stream piping===&lt;br /&gt;
&lt;br /&gt;
Iterators in EiffelBase2 are a special case of streams. Sometimes you can avoid writing a loop by piping an input stream into an output stream, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        array: V_ARRAY [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create array.make (1, 10)&lt;br /&gt;
        -- Fill array with random integers:&lt;br /&gt;
        array.new_cursor.pipe (create {V_RANDOM})&lt;br /&gt;
        -- Fill array with values parsed from a string:&lt;br /&gt;
        array.new_cursor.pipe (create {V_STRING_INPUT [INTEGER]}.make (&amp;quot;1 2 3 4 5 6 7 8 9 10&amp;quot;, agent {STRING}.to_integer))&lt;br /&gt;
        -- Print array elements into standard output:&lt;br /&gt;
        (create {V_STANDARD_OUTPUT}).pipe (array.new_cursor)&lt;br /&gt;
        -- Prints &amp;quot;1 2 3 4 5 6 7 8 9 10 &amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence of elements is a model for a stack or a queue. &lt;br /&gt;
A triple consisting of a reference to the target container, the sequence of elements and an integer is a model for an iterator.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: target, sequence, index&lt;br /&gt;
&lt;br /&gt;
class V_LIST_ITERATOR [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
&lt;br /&gt;
    target: V_LIST&lt;br /&gt;
            -- List to iterate over.&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Current position.&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of elements in `target'.&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;V_LIST_ITERATOR&amp;lt;/e&amp;gt; consisting of tree components: &lt;br /&gt;
a reference (to &amp;lt;e&amp;gt;V_LIST&amp;lt;/e&amp;gt;), a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. &lt;br /&gt;
As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); &lt;br /&gt;
regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;target&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). &lt;br /&gt;
We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
Those annotations can be used by tools to check, if a specification-only feature accidentally got called from non-specification code,&lt;br /&gt;
and to remove such features from the code before compiling it.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of regular features in their terms. &lt;br /&gt;
For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. &lt;br /&gt;
For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments.&lt;br /&gt;
We also supply them with &amp;lt;e&amp;gt;modify&amp;lt;/e&amp;gt; clauses that list all the model queries whose values are allowed to be changed by the command.&lt;br /&gt;
These clauses can be used by tools to generate additional postconditions &amp;lt;e&amp;gt;m = old m&amp;lt;/e&amp;gt; &lt;br /&gt;
for each model query &amp;lt;e&amp;gt;m&amp;lt;/e&amp;gt; of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and other arguments that is not mentioned in the &amp;lt;e&amp;gt;modify&amp;lt;/e&amp;gt; clause.&lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: &lt;br /&gt;
it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;V_LIST_ITERATOR&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: target, sequence, index&lt;br /&gt;
&lt;br /&gt;
class V_LIST_ITERATOR [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position.&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is current position off scope?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Extension&lt;br /&gt;
&lt;br /&gt;
    extend_right (v: G)&lt;br /&gt;
            -- Insert `v' to the right of current position.&lt;br /&gt;
            -- Do not move cursor.&lt;br /&gt;
        note&lt;br /&gt;
            modify: sequence&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
	deferred&lt;br /&gt;
	ensure&lt;br /&gt;
	    sequence_effect: sequence |=| old (sequence.front (index) &amp;amp; v + sequence.tail (index + 1))&lt;br /&gt;
	end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, suppose that &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; inherits directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;, whose model is a bag:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain = sequence.range&lt;br /&gt;
    bag_definition: bag.domain.for all (agent (x: G): BOOLEAN&lt;br /&gt;
        do Result := bag [x] = sequence.occurrences (x) end)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new  model query &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is currently being developed as a project at ETH Zurich.&lt;br /&gt;
It has been used in the following projects:&lt;br /&gt;
* Traffic 4: modeling public transportation in a city [http://traffic.origo.ethz.ch/ http://traffic.origo.ethz.ch/]&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14382</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14382"/>
				<updated>2012-04-05T15:26:05Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Contracts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library, which has for many years played a central role in Eiffel development.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
The latest version of the EiffelBase2 source code is available from the repository: [https://bitbucket.org/nadiapolikarpova/eiffelbase2/ https://bitbucket.org/nadiapolikarpova/eiffelbase2/]&lt;br /&gt;
&lt;br /&gt;
The source code is divided into two clusters:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;structures&amp;lt;/e&amp;gt; - Data Structures, the core of EiffelBase2. The rest of current document is about this cluster.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;mml&amp;lt;/e&amp;gt; - Mathematical Model Library: a library of immutable classes used in ''model-based contracts'' (see below).&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Complete specifications. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
On the top level EiffelBase2 differentiates between ''containers'' and ''streams''. A container is a finite storage of values, while a stream provides linear access to a set of values. A stream is not necessarily bound to a container, e.g. &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; stream observes an infinite sequence of pseudo-random numbers. Streams that traverse containers are called ''iterators''.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies: containers and streams/iterators. &lt;br /&gt;
All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity.&lt;br /&gt;
&lt;br /&gt;
In the diagrams below asterisk and italics font indicates a &amp;lt;e&amp;gt;deferred&amp;lt;/e&amp;gt; class.&lt;br /&gt;
Lighter fill color indicates that the class provides an ''immutable'' interface to the data,&lt;br /&gt;
in other words, it is impossible to modify the content of the container using this interface.&lt;br /&gt;
 &lt;br /&gt;
[[Image:eb2_container.png|1000px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
[[Image:eb2_iterator.png|1000px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
==Usage examples==&lt;br /&gt;
&lt;br /&gt;
===Immutable interfaces===&lt;br /&gt;
With immutable interfaces you can give your clients read-only access to a container you store:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
class TRAM_LINE&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    &lt;br /&gt;
    stations: V_SEQUENCE [STATION]&lt;br /&gt;
            -- Stations on the line.&lt;br /&gt;
            -- (Clients can traverse the stations, but cannot replace them, remove or add new ones.)&lt;br /&gt;
        do&lt;br /&gt;
            Result := station_list&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
feature {NONE} -- Implementation&lt;br /&gt;
&lt;br /&gt;
    station_list: V_LIST [STATION]&lt;br /&gt;
            -- List of line stations.&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Iterators===&lt;br /&gt;
Here is how you can iterate through any container:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    do&lt;br /&gt;
        across&lt;br /&gt;
            container as i&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same thing using the explicit syntax:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        from&lt;br /&gt;
            i := container.new_cursor&lt;br /&gt;
        until&lt;br /&gt;
            i.after&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is some more advanced stuff you can do with lists:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (list: V_LIST [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_LIST_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Find the last 0 at or before position 5:&lt;br /&gt;
        list.at (5).search_back (0)&lt;br /&gt;
        -- Find the first positive element at or after position 5:&lt;br /&gt;
        i := list.at (5)&lt;br /&gt;
        i.satisfy_forth (agent (x: INTEGER): BOOLEAN do Result := x &amp;gt; 0 end)&lt;br /&gt;
        -- And insert a 0 after it:&lt;br /&gt;
        i.extend_right (0)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Sets and tables===&lt;br /&gt;
&lt;br /&gt;
Here is how you create and use a simple hash table (keys must inherit from HASHABLE):&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create table.with_object_equality&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;cat&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you need a custom hash function or equivalence relation on keys, you can use V_GENERAL_HASH_TABLE, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_GENERAL_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Create case-insensitive table:&lt;br /&gt;
        create table.make (&lt;br /&gt;
            agent {STRING}.is_case_insensitive_equal,&lt;br /&gt;
            agent (s: STRING): INTEGER do Result := s.as_lower.hash_code end&lt;br /&gt;
        )&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;CAT&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar style applies to &amp;lt;e&amp;gt;V_HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_HASH_SET&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_TABLE&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_TABLE&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_SET&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Stream piping===&lt;br /&gt;
&lt;br /&gt;
Iterators in EiffelBase2 are a special case of streams. Sometimes you can avoid writing a loop by piping an input stream into an output stream, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        array: V_ARRAY [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create array.make (1, 10)&lt;br /&gt;
        -- Fill array with random integers:&lt;br /&gt;
        array.new_cursor.pipe (create {V_RANDOM})&lt;br /&gt;
        -- Fill array with values parsed from a string:&lt;br /&gt;
        array.new_cursor.pipe (create {V_STRING_INPUT [INTEGER]}.make (&amp;quot;1 2 3 4 5 6 7 8 9 10&amp;quot;, agent {STRING}.to_integer))&lt;br /&gt;
        -- Print array elements into standard output:&lt;br /&gt;
        (create {V_STANDARD_OUTPUT}).pipe (array.new_cursor)&lt;br /&gt;
        -- Prints &amp;quot;1 2 3 4 5 6 7 8 9 10 &amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence of elements is a model for a stack or a queue. &lt;br /&gt;
A triple consisting of a reference to the target container, the sequence of elements and an integer is a model for an iterator.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: target, sequence, index&lt;br /&gt;
class V_ITERATOR [G]&lt;br /&gt;
feature -- Access&lt;br /&gt;
&lt;br /&gt;
    target: V_CONTAINER&lt;br /&gt;
            -- Container to iterate over.&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Current position.&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of elements in `target'.&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;V_ITERATOR&amp;lt;/e&amp;gt; consisting of tree components: &lt;br /&gt;
a reference (to &amp;lt;e&amp;gt;V_CONTAINER&amp;lt;/e&amp;gt;), a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. &lt;br /&gt;
As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); &lt;br /&gt;
regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;target&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). &lt;br /&gt;
We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
Those annotations can be used by tools to check, if a specification-only feature accidentally got called from non-specification code,&lt;br /&gt;
and to remove such features from the code before compiling it.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of regular features in their terms. &lt;br /&gt;
For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. &lt;br /&gt;
For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments.&lt;br /&gt;
We also supply them with &amp;lt;e&amp;gt;modify&amp;lt;/e&amp;gt; clauses that list all the model queries whose values are allowed to be changed by the command.&lt;br /&gt;
These clauses can be used by tools to generate additional postconditions &amp;lt;e&amp;gt;m = old m&amp;lt;/e&amp;gt; &lt;br /&gt;
for each model query &amp;lt;e&amp;gt;m&amp;lt;/e&amp;gt; of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and other arguments that is not mentioned in the &amp;lt;e&amp;gt;modify&amp;lt;/e&amp;gt; clause.&lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: &lt;br /&gt;
it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;V_LIST_ITERATOR&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: target, sequence, index&lt;br /&gt;
&lt;br /&gt;
class V_LIST_ITERATOR [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position.&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is current position off scope?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Extension&lt;br /&gt;
&lt;br /&gt;
    extend_right (v: G)&lt;br /&gt;
            -- Insert `v' to the right of current position.&lt;br /&gt;
            -- Do not move cursor.&lt;br /&gt;
        note&lt;br /&gt;
            modify: sequence&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
	deferred&lt;br /&gt;
	ensure&lt;br /&gt;
	    sequence_effect: sequence |=| old (sequence.front (index) &amp;amp; v + sequence.tail (index + 1))&lt;br /&gt;
	end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, suppose that &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; inherits directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;, whose model is a bag:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain = sequence.range&lt;br /&gt;
    bag_definition: bag.domain.for all (agent (x: G): BOOLEAN&lt;br /&gt;
        do Result := bag [x] = sequence.occurrences (x) end)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new  model query &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is currently being developed as a project at ETH Zurich.&lt;br /&gt;
It has been used in the following projects:&lt;br /&gt;
* Traffic 4: modeling public transportation in a city [http://traffic.origo.ethz.ch/ http://traffic.origo.ethz.ch/]&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14381</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14381"/>
				<updated>2012-04-05T14:38:51Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Models */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library, which has for many years played a central role in Eiffel development.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
The latest version of the EiffelBase2 source code is available from the repository: [https://bitbucket.org/nadiapolikarpova/eiffelbase2/ https://bitbucket.org/nadiapolikarpova/eiffelbase2/]&lt;br /&gt;
&lt;br /&gt;
The source code is divided into two clusters:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;structures&amp;lt;/e&amp;gt; - Data Structures, the core of EiffelBase2. The rest of current document is about this cluster.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;mml&amp;lt;/e&amp;gt; - Mathematical Model Library: a library of immutable classes used in ''model-based contracts'' (see below).&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Complete specifications. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
On the top level EiffelBase2 differentiates between ''containers'' and ''streams''. A container is a finite storage of values, while a stream provides linear access to a set of values. A stream is not necessarily bound to a container, e.g. &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; stream observes an infinite sequence of pseudo-random numbers. Streams that traverse containers are called ''iterators''.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies: containers and streams/iterators. &lt;br /&gt;
All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity.&lt;br /&gt;
&lt;br /&gt;
In the diagrams below asterisk and italics font indicates a &amp;lt;e&amp;gt;deferred&amp;lt;/e&amp;gt; class.&lt;br /&gt;
Lighter fill color indicates that the class provides an ''immutable'' interface to the data,&lt;br /&gt;
in other words, it is impossible to modify the content of the container using this interface.&lt;br /&gt;
 &lt;br /&gt;
[[Image:eb2_container.png|1000px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
[[Image:eb2_iterator.png|1000px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
==Usage examples==&lt;br /&gt;
&lt;br /&gt;
===Immutable interfaces===&lt;br /&gt;
With immutable interfaces you can give your clients read-only access to a container you store:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
class TRAM_LINE&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    &lt;br /&gt;
    stations: V_SEQUENCE [STATION]&lt;br /&gt;
            -- Stations on the line.&lt;br /&gt;
            -- (Clients can traverse the stations, but cannot replace them, remove or add new ones.)&lt;br /&gt;
        do&lt;br /&gt;
            Result := station_list&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
feature {NONE} -- Implementation&lt;br /&gt;
&lt;br /&gt;
    station_list: V_LIST [STATION]&lt;br /&gt;
            -- List of line stations.&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Iterators===&lt;br /&gt;
Here is how you can iterate through any container:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    do&lt;br /&gt;
        across&lt;br /&gt;
            container as i&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same thing using the explicit syntax:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        from&lt;br /&gt;
            i := container.new_cursor&lt;br /&gt;
        until&lt;br /&gt;
            i.after&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is some more advanced stuff you can do with lists:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (list: V_LIST [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_LIST_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Find the last 0 at or before position 5:&lt;br /&gt;
        list.at (5).search_back (0)&lt;br /&gt;
        -- Find the first positive element at or after position 5:&lt;br /&gt;
        i := list.at (5)&lt;br /&gt;
        i.satisfy_forth (agent (x: INTEGER): BOOLEAN do Result := x &amp;gt; 0 end)&lt;br /&gt;
        -- And insert a 0 after it:&lt;br /&gt;
        i.extend_right (0)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Sets and tables===&lt;br /&gt;
&lt;br /&gt;
Here is how you create and use a simple hash table (keys must inherit from HASHABLE):&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create table.with_object_equality&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;cat&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you need a custom hash function or equivalence relation on keys, you can use V_GENERAL_HASH_TABLE, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_GENERAL_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Create case-insensitive table:&lt;br /&gt;
        create table.make (&lt;br /&gt;
            agent {STRING}.is_case_insensitive_equal,&lt;br /&gt;
            agent (s: STRING): INTEGER do Result := s.as_lower.hash_code end&lt;br /&gt;
        )&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;CAT&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar style applies to &amp;lt;e&amp;gt;V_HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_HASH_SET&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_TABLE&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_TABLE&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_SET&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Stream piping===&lt;br /&gt;
&lt;br /&gt;
Iterators in EiffelBase2 are a special case of streams. Sometimes you can avoid writing a loop by piping an input stream into an output stream, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        array: V_ARRAY [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create array.make (1, 10)&lt;br /&gt;
        -- Fill array with random integers:&lt;br /&gt;
        array.new_cursor.pipe (create {V_RANDOM})&lt;br /&gt;
        -- Fill array with values parsed from a string:&lt;br /&gt;
        array.new_cursor.pipe (create {V_STRING_INPUT [INTEGER]}.make (&amp;quot;1 2 3 4 5 6 7 8 9 10&amp;quot;, agent {STRING}.to_integer))&lt;br /&gt;
        -- Print array elements into standard output:&lt;br /&gt;
        (create {V_STANDARD_OUTPUT}).pipe (array.new_cursor)&lt;br /&gt;
        -- Prints &amp;quot;1 2 3 4 5 6 7 8 9 10 &amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence of elements is a model for a stack or a queue. &lt;br /&gt;
A triple consisting of a reference to the target container, the sequence of elements and an integer is a model for an iterator.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: target, sequence, index&lt;br /&gt;
class V_ITERATOR [G]&lt;br /&gt;
feature -- Access&lt;br /&gt;
&lt;br /&gt;
    target: V_CONTAINER&lt;br /&gt;
            -- Container to iterate over.&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Current position.&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of elements in `target'.&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;V_ITERATOR&amp;lt;/e&amp;gt; consisting of tree components: &lt;br /&gt;
a reference (to &amp;lt;e&amp;gt;V_CONTAINER&amp;lt;/e&amp;gt;), a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. &lt;br /&gt;
As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); &lt;br /&gt;
regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;target&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). &lt;br /&gt;
We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
Those annotations can be used by tools to check, if a specification-only feature accidentally got called from non-specification code,&lt;br /&gt;
and to remove such features from the code before compiling it.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of the regular features in their terms. For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. Definitions of zero-argument queries, as usual, can be moved to the class invariant. For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments. If a model query is not mentioned in the postcondition of a command, it is equivalent to stating that it's not modified. &lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is cursor off all elements?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Element change&lt;br /&gt;
    put_right (v: G)&lt;br /&gt;
            -- Put `v' to the right of the cursor&lt;br /&gt;
        require&lt;br /&gt;
            not_after: not after&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            sequence_effect: sequence |=| old (sequence.front (index).extended (v) + sequence.tail (index + 1))&lt;br /&gt;
            index_effect: index = old index&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, suppose that &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; inherits directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;, whose model is a bag:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain = sequence.range&lt;br /&gt;
    bag_definition: bag.domain.for all (agent (x: G): BOOLEAN&lt;br /&gt;
        do Result := bag [x] = sequence.occurrences (x) end)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new  model query &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is currently being developed as a project at ETH Zurich.&lt;br /&gt;
It has been used in the following projects:&lt;br /&gt;
* Traffic 4: modeling public transportation in a city [http://traffic.origo.ethz.ch/ http://traffic.origo.ethz.ch/]&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14380</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14380"/>
				<updated>2012-04-05T14:26:49Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Usage examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library, which has for many years played a central role in Eiffel development.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
The latest version of the EiffelBase2 source code is available from the repository: [https://bitbucket.org/nadiapolikarpova/eiffelbase2/ https://bitbucket.org/nadiapolikarpova/eiffelbase2/]&lt;br /&gt;
&lt;br /&gt;
The source code is divided into two clusters:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;structures&amp;lt;/e&amp;gt; - Data Structures, the core of EiffelBase2. The rest of current document is about this cluster.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;mml&amp;lt;/e&amp;gt; - Mathematical Model Library: a library of immutable classes used in ''model-based contracts'' (see below).&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Complete specifications. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
On the top level EiffelBase2 differentiates between ''containers'' and ''streams''. A container is a finite storage of values, while a stream provides linear access to a set of values. A stream is not necessarily bound to a container, e.g. &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; stream observes an infinite sequence of pseudo-random numbers. Streams that traverse containers are called ''iterators''.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies: containers and streams/iterators. &lt;br /&gt;
All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity.&lt;br /&gt;
&lt;br /&gt;
In the diagrams below asterisk and italics font indicates a &amp;lt;e&amp;gt;deferred&amp;lt;/e&amp;gt; class.&lt;br /&gt;
Lighter fill color indicates that the class provides an ''immutable'' interface to the data,&lt;br /&gt;
in other words, it is impossible to modify the content of the container using this interface.&lt;br /&gt;
 &lt;br /&gt;
[[Image:eb2_container.png|1000px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
[[Image:eb2_iterator.png|1000px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
==Usage examples==&lt;br /&gt;
&lt;br /&gt;
===Immutable interfaces===&lt;br /&gt;
With immutable interfaces you can give your clients read-only access to a container you store:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
class TRAM_LINE&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    &lt;br /&gt;
    stations: V_SEQUENCE [STATION]&lt;br /&gt;
            -- Stations on the line.&lt;br /&gt;
            -- (Clients can traverse the stations, but cannot replace them, remove or add new ones.)&lt;br /&gt;
        do&lt;br /&gt;
            Result := station_list&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
feature {NONE} -- Implementation&lt;br /&gt;
&lt;br /&gt;
    station_list: V_LIST [STATION]&lt;br /&gt;
            -- List of line stations.&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Iterators===&lt;br /&gt;
Here is how you can iterate through any container:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    do&lt;br /&gt;
        across&lt;br /&gt;
            container as i&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same thing using the explicit syntax:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        from&lt;br /&gt;
            i := container.new_cursor&lt;br /&gt;
        until&lt;br /&gt;
            i.after&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is some more advanced stuff you can do with lists:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (list: V_LIST [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_LIST_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Find the last 0 at or before position 5:&lt;br /&gt;
        list.at (5).search_back (0)&lt;br /&gt;
        -- Find the first positive element at or after position 5:&lt;br /&gt;
        i := list.at (5)&lt;br /&gt;
        i.satisfy_forth (agent (x: INTEGER): BOOLEAN do Result := x &amp;gt; 0 end)&lt;br /&gt;
        -- And insert a 0 after it:&lt;br /&gt;
        i.extend_right (0)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Sets and tables===&lt;br /&gt;
&lt;br /&gt;
Here is how you create and use a simple hash table (keys must inherit from HASHABLE):&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create table.with_object_equality&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;cat&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you need a custom hash function or equivalence relation on keys, you can use V_GENERAL_HASH_TABLE, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_GENERAL_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Create case-insensitive table:&lt;br /&gt;
        create table.make (&lt;br /&gt;
            agent {STRING}.is_case_insensitive_equal,&lt;br /&gt;
            agent (s: STRING): INTEGER do Result := s.as_lower.hash_code end&lt;br /&gt;
        )&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;CAT&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar style applies to &amp;lt;e&amp;gt;V_HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_HASH_SET&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_TABLE&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_TABLE&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_SET&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Stream piping===&lt;br /&gt;
&lt;br /&gt;
Iterators in EiffelBase2 are a special case of streams. Sometimes you can avoid writing a loop by piping an input stream into an output stream, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        array: V_ARRAY [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create array.make (1, 10)&lt;br /&gt;
        -- Fill array with random integers:&lt;br /&gt;
        array.new_cursor.pipe (create {V_RANDOM})&lt;br /&gt;
        -- Fill array with values parsed from a string:&lt;br /&gt;
        array.new_cursor.pipe (create {V_STRING_INPUT [INTEGER]}.make (&amp;quot;1 2 3 4 5 6 7 8 9 10&amp;quot;, agent {STRING}.to_integer))&lt;br /&gt;
        -- Print array elements into standard output:&lt;br /&gt;
        (create {V_STANDARD_OUTPUT}).pipe (array.new_cursor)&lt;br /&gt;
        -- Prints &amp;quot;1 2 3 4 5 6 7 8 9 10 &amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence is a model for a stack or a queue. A pair consisting of a sequence and an integer is a model for a list with an internal cursor.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
feature -- Access&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Cursor position&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of list elements&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; consisting of two components: a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of the regular features in their terms. For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. Definitions of zero-argument queries, as usual, can be moved to the class invariant. For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments. If a model query is not mentioned in the postcondition of a command, it is equivalent to stating that it's not modified. &lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is cursor off all elements?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Element change&lt;br /&gt;
    put_right (v: G)&lt;br /&gt;
            -- Put `v' to the right of the cursor&lt;br /&gt;
        require&lt;br /&gt;
            not_after: not after&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            sequence_effect: sequence |=| old (sequence.front (index).extended (v) + sequence.tail (index + 1))&lt;br /&gt;
            index_effect: index = old index&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, suppose that &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; inherits directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;, whose model is a bag:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain = sequence.range&lt;br /&gt;
    bag_definition: bag.domain.for all (agent (x: G): BOOLEAN&lt;br /&gt;
        do Result := bag [x] = sequence.occurrences (x) end)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new  model query &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is currently being developed as a project at ETH Zurich.&lt;br /&gt;
It has been used in the following projects:&lt;br /&gt;
* Traffic 4: modeling public transportation in a city [http://traffic.origo.ethz.ch/ http://traffic.origo.ethz.ch/]&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14378</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14378"/>
				<updated>2012-04-05T13:47:02Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library, which has for many years played a central role in Eiffel development.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
The latest version of the EiffelBase2 source code is available from the repository: [https://bitbucket.org/nadiapolikarpova/eiffelbase2/ https://bitbucket.org/nadiapolikarpova/eiffelbase2/]&lt;br /&gt;
&lt;br /&gt;
The source code is divided into two clusters:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;structures&amp;lt;/e&amp;gt; - Data Structures, the core of EiffelBase2. The rest of current document is about this cluster.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;mml&amp;lt;/e&amp;gt; - Mathematical Model Library: a library of immutable classes used in ''model-based contracts'' (see below).&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Complete specifications. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
On the top level EiffelBase2 differentiates between ''containers'' and ''streams''. A container is a finite storage of values, while a stream provides linear access to a set of values. A stream is not necessarily bound to a container, e.g. &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; stream observes an infinite sequence of pseudo-random numbers. Streams that traverse containers are called ''iterators''.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies: containers and streams/iterators. &lt;br /&gt;
All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity.&lt;br /&gt;
&lt;br /&gt;
In the diagrams below asterisk and italics font indicates a &amp;lt;e&amp;gt;deferred&amp;lt;/e&amp;gt; class.&lt;br /&gt;
Lighter fill color indicates that the class provides an ''immutable'' interface to the data,&lt;br /&gt;
in other words, it is impossible to modify the content of the container using this interface.&lt;br /&gt;
 &lt;br /&gt;
[[Image:eb2_container.png|1000px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
[[Image:eb2_iterator.png|1000px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
==Usage examples==&lt;br /&gt;
&lt;br /&gt;
===Iterators===&lt;br /&gt;
Here is how you can iterate through any container:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    do&lt;br /&gt;
        across&lt;br /&gt;
            container as i&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same thing using the explicit syntax:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        from&lt;br /&gt;
            i := container.new_cursor&lt;br /&gt;
        until&lt;br /&gt;
            i.after&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is some more advanced stuff you can do with lists:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (list: V_LIST [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_LIST_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Find the last 0 at or before position 5:&lt;br /&gt;
        list.at (5).search_back (0)&lt;br /&gt;
        -- Find the first positive element at or after position 5:&lt;br /&gt;
        i := list.at (5)&lt;br /&gt;
        i.satisfy_forth (agent (x: INTEGER): BOOLEAN do Result := x &amp;gt; 0 end)&lt;br /&gt;
        -- And insert a 0 after it:&lt;br /&gt;
        i.extend_right (0)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Sets and tables===&lt;br /&gt;
&lt;br /&gt;
Here is how you create and use a simple hash table (keys must inherit from HASHABLE):&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create table.with_object_equality&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;cat&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you need a custom hash function or equivalence relation on keys, you can use V_GENERAL_HASH_TABLE, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_GENERAL_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Create case-insensitive table:&lt;br /&gt;
        create table.make (&lt;br /&gt;
            agent {STRING}.is_case_insensitive_equal,&lt;br /&gt;
            agent (s: STRING): INTEGER do Result := s.as_lower.hash_code end&lt;br /&gt;
        )&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;CAT&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar style applies to &amp;lt;e&amp;gt;V_HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_HASH_SET&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_TABLE&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_TABLE&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_SET&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Stream piping===&lt;br /&gt;
&lt;br /&gt;
Iterators in EiffelBase2 are a special case of streams. Sometimes you can avoid writing a loop by piping an input stream into an output stream, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        array: V_ARRAY [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create array.make (1, 10)&lt;br /&gt;
        -- Fill array with random integers:&lt;br /&gt;
        array.new_cursor.pipe (create {V_RANDOM})&lt;br /&gt;
        -- Fill array with values parsed from a string:&lt;br /&gt;
        array.new_cursor.pipe (create {V_STRING_INPUT [INTEGER]}.make (&amp;quot;1 2 3 4 5 6 7 8 9 10&amp;quot;, agent {STRING}.to_integer))&lt;br /&gt;
        -- Print array elements into standard output:&lt;br /&gt;
        (create {V_STANDARD_OUTPUT}).pipe (array.new_cursor)&lt;br /&gt;
        -- Prints &amp;quot;1 2 3 4 5 6 7 8 9 10 &amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence is a model for a stack or a queue. A pair consisting of a sequence and an integer is a model for a list with an internal cursor.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
feature -- Access&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Cursor position&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of list elements&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; consisting of two components: a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of the regular features in their terms. For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. Definitions of zero-argument queries, as usual, can be moved to the class invariant. For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments. If a model query is not mentioned in the postcondition of a command, it is equivalent to stating that it's not modified. &lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is cursor off all elements?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Element change&lt;br /&gt;
    put_right (v: G)&lt;br /&gt;
            -- Put `v' to the right of the cursor&lt;br /&gt;
        require&lt;br /&gt;
            not_after: not after&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            sequence_effect: sequence |=| old (sequence.front (index).extended (v) + sequence.tail (index + 1))&lt;br /&gt;
            index_effect: index = old index&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, suppose that &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; inherits directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;, whose model is a bag:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain = sequence.range&lt;br /&gt;
    bag_definition: bag.domain.for all (agent (x: G): BOOLEAN&lt;br /&gt;
        do Result := bag [x] = sequence.occurrences (x) end)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new  model query &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is currently being developed as a project at ETH Zurich.&lt;br /&gt;
It has been used in the following projects:&lt;br /&gt;
* Traffic 4: modeling public transportation in a city [http://traffic.origo.ethz.ch/ http://traffic.origo.ethz.ch/]&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=File:Eb2_iterator.png&amp;diff=14377</id>
		<title>File:Eb2 iterator.png</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=File:Eb2_iterator.png&amp;diff=14377"/>
				<updated>2012-04-05T13:40:05Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: uploaded a new version of &amp;quot;Image:Eb2 iterator.png&amp;quot;: Iterator hierarchy of EiffelBase2&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Class diagram of the iterator classes in EiffelBase2 library.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=File:Eb2_container.png&amp;diff=14376</id>
		<title>File:Eb2 container.png</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=File:Eb2_container.png&amp;diff=14376"/>
				<updated>2012-04-05T13:39:01Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: uploaded a new version of &amp;quot;Image:Eb2 container.png&amp;quot;: Container Hierarchy of EiffelBase2&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Class diagram of the container classes in EiffelBase2 library.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14375</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14375"/>
				<updated>2012-04-05T13:37:30Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library, which has for many years played a central role in Eiffel development.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
The latest version of the EiffelBase2 source code is available from the repository: [https://bitbucket.org/nadiapolikarpova/eiffelbase2/ https://bitbucket.org/nadiapolikarpova/eiffelbase2/]&lt;br /&gt;
&lt;br /&gt;
The source code is divided into two clusters:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;structures&amp;lt;/e&amp;gt; - Data Structures, the core of EiffelBase2. The rest of current document is about this cluster.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;e&amp;gt;mml&amp;lt;/e&amp;gt; - Mathematical Model Library: a library of immutable classes used in ''model-based contracts'' (see below).&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Complete specifications. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
On the top level EiffelBase2 differentiates between ''containers'' and ''streams''. A container is a finite storage of values, while a stream provides linear access to a set of values. A stream is not necessarily bound to a container, e.g. &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; stream observes an infinite sequence of pseudo-random numbers. Streams that traverse containers are called ''iterators''.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies: containers and streams/iterators. All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity. &lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
==Usage examples==&lt;br /&gt;
&lt;br /&gt;
===Iterators===&lt;br /&gt;
Here is how you can iterate through any container:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    do&lt;br /&gt;
        across&lt;br /&gt;
            container as i&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same thing using the explicit syntax:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        from&lt;br /&gt;
            i := container.new_cursor&lt;br /&gt;
        until&lt;br /&gt;
            i.after&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is some more advanced stuff you can do with lists:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (list: V_LIST [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_LIST_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Find the last 0 at or before position 5:&lt;br /&gt;
        list.at (5).search_back (0)&lt;br /&gt;
        -- Find the first positive element at or after position 5:&lt;br /&gt;
        i := list.at (5)&lt;br /&gt;
        i.satisfy_forth (agent (x: INTEGER): BOOLEAN do Result := x &amp;gt; 0 end)&lt;br /&gt;
        -- And insert a 0 after it:&lt;br /&gt;
        i.extend_right (0)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Sets and tables===&lt;br /&gt;
&lt;br /&gt;
Here is how you create and use a simple hash table (keys must inherit from HASHABLE):&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create table.with_object_equality&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;cat&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you need a custom hash function or equivalence relation on keys, you can use V_GENERAL_HASH_TABLE, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_GENERAL_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Create case-insensitive table:&lt;br /&gt;
        create table.make (&lt;br /&gt;
            agent {STRING}.is_case_insensitive_equal,&lt;br /&gt;
            agent (s: STRING): INTEGER do Result := s.as_lower.hash_code end&lt;br /&gt;
        )&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;CAT&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar style applies to &amp;lt;e&amp;gt;V_HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_HASH_SET&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_TABLE&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_TABLE&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_SET&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Stream piping===&lt;br /&gt;
&lt;br /&gt;
Iterators in EiffelBase2 are a special case of streams. Sometimes you can avoid writing a loop by piping an input stream into an output stream, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        array: V_ARRAY [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create array.make (1, 10)&lt;br /&gt;
        -- Fill array with random integers:&lt;br /&gt;
        array.new_cursor.pipe (create {V_RANDOM})&lt;br /&gt;
        -- Fill array with values parsed from a string:&lt;br /&gt;
        array.new_cursor.pipe (create {V_STRING_INPUT [INTEGER]}.make (&amp;quot;1 2 3 4 5 6 7 8 9 10&amp;quot;, agent {STRING}.to_integer))&lt;br /&gt;
        -- Print array elements into standard output:&lt;br /&gt;
        (create {V_STANDARD_OUTPUT}).pipe (array.new_cursor)&lt;br /&gt;
        -- Prints &amp;quot;1 2 3 4 5 6 7 8 9 10 &amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence is a model for a stack or a queue. A pair consisting of a sequence and an integer is a model for a list with an internal cursor.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
feature -- Access&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Cursor position&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of list elements&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; consisting of two components: a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of the regular features in their terms. For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. Definitions of zero-argument queries, as usual, can be moved to the class invariant. For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments. If a model query is not mentioned in the postcondition of a command, it is equivalent to stating that it's not modified. &lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is cursor off all elements?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Element change&lt;br /&gt;
    put_right (v: G)&lt;br /&gt;
            -- Put `v' to the right of the cursor&lt;br /&gt;
        require&lt;br /&gt;
            not_after: not after&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            sequence_effect: sequence |=| old (sequence.front (index).extended (v) + sequence.tail (index + 1))&lt;br /&gt;
            index_effect: index = old index&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, suppose that &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; inherits directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;, whose model is a bag:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain = sequence.range&lt;br /&gt;
    bag_definition: bag.domain.for all (agent (x: G): BOOLEAN&lt;br /&gt;
        do Result := bag [x] = sequence.occurrences (x) end)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new  model query &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is currently being developed as a project at ETH Zurich.&lt;br /&gt;
It has been used in the following projects:&lt;br /&gt;
* Traffic 4: modeling public transportation in a city [http://traffic.origo.ethz.ch/ http://traffic.origo.ethz.ch/]&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14101</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14101"/>
				<updated>2011-05-02T13:16:48Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* ToDo list */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library, which has for many years played a central role in Eiffel development.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
You can download a stable release of EiffelBase2 from the downloads page: [http://eiffelbase2.origo.ethz.ch/download http://eiffelbase2.origo.ethz.ch/download]&lt;br /&gt;
&lt;br /&gt;
The latest version of the EiffelBase2 source code is available in the repository: [https://svn.origo.ethz.ch/eiffelbase2/trunk/ https://svn.origo.ethz.ch/eiffelbase2/trunk/]&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Complete specifications. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
On the top level EiffelBase2 differentiates between ''containers'' and interfaces to access elements of containers, called ''accessors''. A container is a finite storage of values. Accessors are either ''maps'' (accessing elements by a unique key) or ''streams'' (linear access). An observer is not necessarily bound to a container, e.g. &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; stream observes an infinite sequence of pseudo-random numbers. Streams that traverse containers are called ''iterators''.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies. The first one is a hierarchy of containers and maps. All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity. &lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
The second one is a hierarchy of streams and iterators.&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
==Usage examples==&lt;br /&gt;
&lt;br /&gt;
===Iterators===&lt;br /&gt;
Here is how you can iterate through any container:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_INPUT_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        from&lt;br /&gt;
            i := container.new_iterator&lt;br /&gt;
        until&lt;br /&gt;
            i.after&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is some more advanced stuff you can do with lists:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (list: V_LIST [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_LIST_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Find the last 0 at or before position 5:&lt;br /&gt;
        list.at (5).search_back (0)&lt;br /&gt;
        -- Find the first positive element at or after position 5:&lt;br /&gt;
        i := list.at (5)&lt;br /&gt;
        i.satisfy_forth (agent (x: INTEGER): BOOLEAN do Result := x &amp;gt; 0 end)&lt;br /&gt;
        -- And insert a 0 after it:&lt;br /&gt;
        i.extend_right (0)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Sets and tables===&lt;br /&gt;
&lt;br /&gt;
Here is how you create and use a simple hash table (keys must inherit from HASHABLE):&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create table.with_object_equality&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;cat&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you need a custom hash function or equivalence relation on keys, you can use V_GENERAL_HASH_TABLE, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_GENERAL_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Create case-insensitive table:&lt;br /&gt;
        create table.make (&lt;br /&gt;
            agent {STRING}.is_case_insensitive_equal,&lt;br /&gt;
            agent (s: STRING): INTEGER do Result := s.as_lower.hash_code end&lt;br /&gt;
        )&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;CAT&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar style applies to &amp;lt;e&amp;gt;V_HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_HASH_SET&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_TABLE&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_TABLE&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_SET&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Stream piping===&lt;br /&gt;
&lt;br /&gt;
Iterators in EiffelBase2 are a special case of streams. Sometimes you can avoid writing a loop by piping an input stream into an output stream, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        array: V_ARRAY [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create array.make (1, 10)&lt;br /&gt;
        -- Fill array with random integers:&lt;br /&gt;
        array.at_first.pipe (create {V_RANDOM})&lt;br /&gt;
        -- Fill array with values parsed from a string:&lt;br /&gt;
        array.at_first.pipe (create {V_STRING_INPUT [INTEGER]}.make (&amp;quot;1 2 3 4 5 6 7 8 9 10&amp;quot;, agent {STRING}.to_integer))&lt;br /&gt;
        -- Print array elements into standard output:&lt;br /&gt;
        (create {V_STANDARD_OUTPUT}).pipe (array.at_first)&lt;br /&gt;
        -- Prints &amp;quot;1 2 3 4 5 6 7 8 9 10 &amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence is a model for a stack or a queue. A pair consisting of a sequence and an integer is a model for a list with an internal cursor.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
feature -- Access&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Cursor position&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of list elements&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; consisting of two components: a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of the regular features in their terms. For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. Definitions of zero-argument queries, as usual, can be moved to the class invariant. For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments. If a model query is not mentioned in the postcondition of a command, it is equivalent to stating that it's not modified. &lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is cursor off all elements?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Element change&lt;br /&gt;
    put_right (v: G)&lt;br /&gt;
            -- Put `v' to the right of the cursor&lt;br /&gt;
        require&lt;br /&gt;
            not_after: not after&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            sequence_effect: sequence |=| old (sequence.front (index).extended (v) + sequence.tail (index + 1))&lt;br /&gt;
            index_effect: index = old index&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, suppose that &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; inherits directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;, whose model is a bag:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain = sequence.range&lt;br /&gt;
    bag_definition: bag.domain.for all (agent (x: G): BOOLEAN&lt;br /&gt;
        do Result := bag [x] = sequence.occurrences (x) end)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new  model query &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is currently being developed as a project at ETH Zurich.&lt;br /&gt;
&lt;br /&gt;
===ToDo list===&lt;br /&gt;
* Add support for the &amp;lt;e&amp;gt;across&amp;lt;/e&amp;gt; syntax.&lt;br /&gt;
* Add more useful streams and iterators (for filtering, mapping, folding, extending lists).&lt;br /&gt;
* Add immutable and mutable strings.&lt;br /&gt;
* Make model class implementation more efficient.&lt;br /&gt;
* Add files and directories.&lt;br /&gt;
* Add an iterator over keys for &amp;lt;e&amp;gt;TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Make the library void-safe.&lt;br /&gt;
* Implement more efficient data structures: e.g., tables with fast lookup both ways, heaps, skip lists, treaps, etc.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14100</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14100"/>
				<updated>2011-05-02T13:14:21Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Sets and tables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library, which has for many years played a central role in Eiffel development.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
You can download a stable release of EiffelBase2 from the downloads page: [http://eiffelbase2.origo.ethz.ch/download http://eiffelbase2.origo.ethz.ch/download]&lt;br /&gt;
&lt;br /&gt;
The latest version of the EiffelBase2 source code is available in the repository: [https://svn.origo.ethz.ch/eiffelbase2/trunk/ https://svn.origo.ethz.ch/eiffelbase2/trunk/]&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Complete specifications. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
On the top level EiffelBase2 differentiates between ''containers'' and interfaces to access elements of containers, called ''accessors''. A container is a finite storage of values. Accessors are either ''maps'' (accessing elements by a unique key) or ''streams'' (linear access). An observer is not necessarily bound to a container, e.g. &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; stream observes an infinite sequence of pseudo-random numbers. Streams that traverse containers are called ''iterators''.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies. The first one is a hierarchy of containers and maps. All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity. &lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
The second one is a hierarchy of streams and iterators.&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
==Usage examples==&lt;br /&gt;
&lt;br /&gt;
===Iterators===&lt;br /&gt;
Here is how you can iterate through any container:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_INPUT_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        from&lt;br /&gt;
            i := container.new_iterator&lt;br /&gt;
        until&lt;br /&gt;
            i.after&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is some more advanced stuff you can do with lists:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (list: V_LIST [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_LIST_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Find the last 0 at or before position 5:&lt;br /&gt;
        list.at (5).search_back (0)&lt;br /&gt;
        -- Find the first positive element at or after position 5:&lt;br /&gt;
        i := list.at (5)&lt;br /&gt;
        i.satisfy_forth (agent (x: INTEGER): BOOLEAN do Result := x &amp;gt; 0 end)&lt;br /&gt;
        -- And insert a 0 after it:&lt;br /&gt;
        i.extend_right (0)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Sets and tables===&lt;br /&gt;
&lt;br /&gt;
Here is how you create and use a simple hash table (keys must inherit from HASHABLE):&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create table.with_object_equality&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;cat&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you need a custom hash function or equivalence relation on keys, you can use V_GENERAL_HASH_TABLE, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_GENERAL_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Create case-insensitive table:&lt;br /&gt;
        create table.make (&lt;br /&gt;
            agent {STRING}.is_case_insensitive_equal,&lt;br /&gt;
            agent (s: STRING): INTEGER do Result := s.as_lower.hash_code end&lt;br /&gt;
        )&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;CAT&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar style applies to &amp;lt;e&amp;gt;V_HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_HASH_SET&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_TABLE&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_TABLE&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_SET&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Stream piping===&lt;br /&gt;
&lt;br /&gt;
Iterators in EiffelBase2 are a special case of streams. Sometimes you can avoid writing a loop by piping an input stream into an output stream, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        array: V_ARRAY [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create array.make (1, 10)&lt;br /&gt;
        -- Fill array with random integers:&lt;br /&gt;
        array.at_first.pipe (create {V_RANDOM})&lt;br /&gt;
        -- Fill array with values parsed from a string:&lt;br /&gt;
        array.at_first.pipe (create {V_STRING_INPUT [INTEGER]}.make (&amp;quot;1 2 3 4 5 6 7 8 9 10&amp;quot;, agent {STRING}.to_integer))&lt;br /&gt;
        -- Print array elements into standard output:&lt;br /&gt;
        (create {V_STANDARD_OUTPUT}).pipe (array.at_first)&lt;br /&gt;
        -- Prints &amp;quot;1 2 3 4 5 6 7 8 9 10 &amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence is a model for a stack or a queue. A pair consisting of a sequence and an integer is a model for a list with an internal cursor.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
feature -- Access&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Cursor position&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of list elements&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; consisting of two components: a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of the regular features in their terms. For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. Definitions of zero-argument queries, as usual, can be moved to the class invariant. For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments. If a model query is not mentioned in the postcondition of a command, it is equivalent to stating that it's not modified. &lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is cursor off all elements?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Element change&lt;br /&gt;
    put_right (v: G)&lt;br /&gt;
            -- Put `v' to the right of the cursor&lt;br /&gt;
        require&lt;br /&gt;
            not_after: not after&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            sequence_effect: sequence |=| old (sequence.front (index).extended (v) + sequence.tail (index + 1))&lt;br /&gt;
            index_effect: index = old index&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, suppose that &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; inherits directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;, whose model is a bag:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain = sequence.range&lt;br /&gt;
    bag_definition: bag.domain.for all (agent (x: G): BOOLEAN&lt;br /&gt;
        do Result := bag [x] = sequence.occurrences (x) end)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new  model query &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is currently being developed as a project at ETH Zurich.&lt;br /&gt;
&lt;br /&gt;
===ToDo list===&lt;br /&gt;
* Add immutable and mutable strings.&lt;br /&gt;
* Make model class implementation more efficient.&lt;br /&gt;
* Add classes and directories.&lt;br /&gt;
* Rewrite loops using the &amp;lt;e&amp;gt;across&amp;lt;/e&amp;gt; where appropriate.&lt;br /&gt;
* Add an iterator over keys for &amp;lt;e&amp;gt;TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Make the library void-safe.&lt;br /&gt;
* Implement more efficient data structures: e.g., tables with fast lookup both ways, heaps, skip lists, treaps, etc.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14099</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14099"/>
				<updated>2011-05-02T13:13:58Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Download */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library, which has for many years played a central role in Eiffel development.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
You can download a stable release of EiffelBase2 from the downloads page: [http://eiffelbase2.origo.ethz.ch/download http://eiffelbase2.origo.ethz.ch/download]&lt;br /&gt;
&lt;br /&gt;
The latest version of the EiffelBase2 source code is available in the repository: [https://svn.origo.ethz.ch/eiffelbase2/trunk/ https://svn.origo.ethz.ch/eiffelbase2/trunk/]&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Complete specifications. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
On the top level EiffelBase2 differentiates between ''containers'' and interfaces to access elements of containers, called ''accessors''. A container is a finite storage of values. Accessors are either ''maps'' (accessing elements by a unique key) or ''streams'' (linear access). An observer is not necessarily bound to a container, e.g. &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; stream observes an infinite sequence of pseudo-random numbers. Streams that traverse containers are called ''iterators''.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies. The first one is a hierarchy of containers and maps. All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity. &lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
The second one is a hierarchy of streams and iterators.&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
==Usage examples==&lt;br /&gt;
&lt;br /&gt;
===Iterators===&lt;br /&gt;
Here is how you can iterate through any container:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_INPUT_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        from&lt;br /&gt;
            i := container.new_iterator&lt;br /&gt;
        until&lt;br /&gt;
            i.after&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is some more advanced stuff you can do with lists:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (list: V_LIST [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_LIST_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Find the last 0 at or before position 5:&lt;br /&gt;
        list.at (5).search_back (0)&lt;br /&gt;
        -- Find the first positive element at or after position 5:&lt;br /&gt;
        i := list.at (5)&lt;br /&gt;
        i.satisfy_forth (agent (x: INTEGER): BOOLEAN do Result := x &amp;gt; 0 end)&lt;br /&gt;
        -- And insert a 0 after it:&lt;br /&gt;
        i.extend_right (0)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Sets and tables===&lt;br /&gt;
&lt;br /&gt;
Here is how you create and use a simple has table (keys must inherit from HASHABLE):&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create table.with_object_equality&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;cat&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you need a custom hash function or equivalence relation on keys, you can use V_GENERAL_HASH_TABLE, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_GENERAL_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Create case-insensitive table:&lt;br /&gt;
        create table.make (&lt;br /&gt;
            agent {STRING}.is_case_insensitive_equal,&lt;br /&gt;
            agent (s: STRING): INTEGER do Result := s.as_lower.hash_code end&lt;br /&gt;
        )&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;CAT&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar style applies to &amp;lt;e&amp;gt;V_HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_HASH_SET&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_TABLE&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_TABLE&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_SET&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Stream piping===&lt;br /&gt;
&lt;br /&gt;
Iterators in EiffelBase2 are a special case of streams. Sometimes you can avoid writing a loop by piping an input stream into an output stream, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        array: V_ARRAY [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create array.make (1, 10)&lt;br /&gt;
        -- Fill array with random integers:&lt;br /&gt;
        array.at_first.pipe (create {V_RANDOM})&lt;br /&gt;
        -- Fill array with values parsed from a string:&lt;br /&gt;
        array.at_first.pipe (create {V_STRING_INPUT [INTEGER]}.make (&amp;quot;1 2 3 4 5 6 7 8 9 10&amp;quot;, agent {STRING}.to_integer))&lt;br /&gt;
        -- Print array elements into standard output:&lt;br /&gt;
        (create {V_STANDARD_OUTPUT}).pipe (array.at_first)&lt;br /&gt;
        -- Prints &amp;quot;1 2 3 4 5 6 7 8 9 10 &amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence is a model for a stack or a queue. A pair consisting of a sequence and an integer is a model for a list with an internal cursor.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
feature -- Access&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Cursor position&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of list elements&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; consisting of two components: a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of the regular features in their terms. For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. Definitions of zero-argument queries, as usual, can be moved to the class invariant. For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments. If a model query is not mentioned in the postcondition of a command, it is equivalent to stating that it's not modified. &lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is cursor off all elements?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Element change&lt;br /&gt;
    put_right (v: G)&lt;br /&gt;
            -- Put `v' to the right of the cursor&lt;br /&gt;
        require&lt;br /&gt;
            not_after: not after&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            sequence_effect: sequence |=| old (sequence.front (index).extended (v) + sequence.tail (index + 1))&lt;br /&gt;
            index_effect: index = old index&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, suppose that &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; inherits directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;, whose model is a bag:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain = sequence.range&lt;br /&gt;
    bag_definition: bag.domain.for all (agent (x: G): BOOLEAN&lt;br /&gt;
        do Result := bag [x] = sequence.occurrences (x) end)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new  model query &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is currently being developed as a project at ETH Zurich.&lt;br /&gt;
&lt;br /&gt;
===ToDo list===&lt;br /&gt;
* Add immutable and mutable strings.&lt;br /&gt;
* Make model class implementation more efficient.&lt;br /&gt;
* Add classes and directories.&lt;br /&gt;
* Rewrite loops using the &amp;lt;e&amp;gt;across&amp;lt;/e&amp;gt; where appropriate.&lt;br /&gt;
* Add an iterator over keys for &amp;lt;e&amp;gt;TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Make the library void-safe.&lt;br /&gt;
* Implement more efficient data structures: e.g., tables with fast lookup both ways, heaps, skip lists, treaps, etc.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14079</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14079"/>
				<updated>2011-03-21T18:59:39Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library, which has for many years played a central role in Eiffel development.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
The latest version of the EiffelBase2 source code is available in the repository: [https://svn.origo.ethz.ch/eiffelbase2/trunk/ https://svn.origo.ethz.ch/eiffelbase2/trunk/]&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Complete specifications. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
On the top level EiffelBase2 differentiates between ''containers'' and interfaces to access elements of containers, called ''accessors''. A container is a finite storage of values. Accessors are either ''maps'' (accessing elements by a unique key) or ''streams'' (linear access). An observer is not necessarily bound to a container, e.g. &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; stream observes an infinite sequence of pseudo-random numbers. Streams that traverse containers are called ''iterators''.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies. The first one is a hierarchy of containers and maps. All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity. &lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
The second one is a hierarchy of streams and iterators.&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
==Usage examples==&lt;br /&gt;
&lt;br /&gt;
===Iterators===&lt;br /&gt;
Here is how you can iterate through any container:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (container: V_CONTAINER [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_INPUT_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        from&lt;br /&gt;
            i := container.new_iterator&lt;br /&gt;
        until&lt;br /&gt;
            i.after&lt;br /&gt;
        loop&lt;br /&gt;
            print (i.item)&lt;br /&gt;
            i.forth&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is some more advanced stuff you can do with lists:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something (list: V_LIST [INTEGER])&lt;br /&gt;
    local&lt;br /&gt;
        i: V_LIST_ITERATOR [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Find the last 0 at or before position 5:&lt;br /&gt;
        list.at (5).search_back (0)&lt;br /&gt;
        -- Find the first positive element at or after position 5:&lt;br /&gt;
        i := list.at (5)&lt;br /&gt;
        i.satisfy_forth (agent (x: INTEGER): BOOLEAN do Result := x &amp;gt; 0 end)&lt;br /&gt;
        -- And insert a 0 after it:&lt;br /&gt;
        i.extend_right (0)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Sets and tables===&lt;br /&gt;
&lt;br /&gt;
Here is how you create and use a simple has table (keys must inherit from HASHABLE):&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create table.with_object_equality&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;cat&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you need a custom hash function or equivalence relation on keys, you can use V_GENERAL_HASH_TABLE, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        table: V_GENERAL_HASH_TABLE [STRING, INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        -- Create case-insensitive table:&lt;br /&gt;
        create table.make (&lt;br /&gt;
            agent {STRING}.is_case_insensitive_equal,&lt;br /&gt;
            agent (s: STRING): INTEGER do Result := s.as_lower.hash_code end&lt;br /&gt;
        )&lt;br /&gt;
        table [&amp;quot;cat&amp;quot;] := 1&lt;br /&gt;
        table [&amp;quot;dog&amp;quot;] := 2&lt;br /&gt;
        print (table [&amp;quot;CAT&amp;quot;] + table [&amp;quot;dog&amp;quot;])&lt;br /&gt;
        -- Prints &amp;quot;3&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar style applies to &amp;lt;e&amp;gt;V_HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_HASH_SET&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_TABLE&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_TABLE&amp;lt;/e&amp;gt;, &amp;lt;e&amp;gt;V_SORTED_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;V_GENERAL_SORTED_SET&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Stream piping===&lt;br /&gt;
&lt;br /&gt;
Iterators in EiffelBase2 are a special case of streams. Sometimes you can avoid writing a loop by piping an input stream into an output stream, for example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
do_something&lt;br /&gt;
    local&lt;br /&gt;
        array: V_ARRAY [INTEGER]&lt;br /&gt;
    do&lt;br /&gt;
        create array.make (1, 10)&lt;br /&gt;
        -- Fill array with random integers:&lt;br /&gt;
        array.at_first.pipe (create {V_RANDOM})&lt;br /&gt;
        -- Fill array with values parsed from a string:&lt;br /&gt;
        array.at_first.pipe (create {V_STRING_INPUT [INTEGER]}.make (&amp;quot;1 2 3 4 5 6 7 8 9 10&amp;quot;, agent {STRING}.to_integer))&lt;br /&gt;
        -- Print array elements into standard output:&lt;br /&gt;
        (create {V_STANDARD_OUTPUT}).pipe (array.at_first)&lt;br /&gt;
        -- Prints &amp;quot;1 2 3 4 5 6 7 8 9 10 &amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence is a model for a stack or a queue. A pair consisting of a sequence and an integer is a model for a list with an internal cursor.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
feature -- Access&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Cursor position&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of list elements&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; consisting of two components: a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of the regular features in their terms. For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. Definitions of zero-argument queries, as usual, can be moved to the class invariant. For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments. If a model query is not mentioned in the postcondition of a command, it is equivalent to stating that it's not modified. &lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is cursor off all elements?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Element change&lt;br /&gt;
    put_right (v: G)&lt;br /&gt;
            -- Put `v' to the right of the cursor&lt;br /&gt;
        require&lt;br /&gt;
            not_after: not after&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            sequence_effect: sequence |=| old (sequence.front (index).extended (v) + sequence.tail (index + 1))&lt;br /&gt;
            index_effect: index = old index&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, suppose that &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; inherits directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;, whose model is a bag:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain = sequence.range&lt;br /&gt;
    bag_definition: bag.domain.for all (agent (x: G): BOOLEAN&lt;br /&gt;
        do Result := bag [x] = sequence.occurrences (x) end)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new  model query &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is currently being developed as a project at ETH Zurich.&lt;br /&gt;
&lt;br /&gt;
===ToDo list===&lt;br /&gt;
* Add immutable and mutable strings.&lt;br /&gt;
* Make model class implementation more efficient.&lt;br /&gt;
* Add classes and directories.&lt;br /&gt;
* Rewrite loops using the &amp;lt;e&amp;gt;across&amp;lt;/e&amp;gt; where appropriate.&lt;br /&gt;
* Add an iterator over keys for &amp;lt;e&amp;gt;TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Make the library void-safe.&lt;br /&gt;
* Implement more efficient data structures: e.g., tables with fast lookup both ways, heaps, skip lists, treaps, etc.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=File:Eb2_container.png&amp;diff=14078</id>
		<title>File:Eb2 container.png</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=File:Eb2_container.png&amp;diff=14078"/>
				<updated>2011-03-21T17:48:26Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: uploaded a new version of &amp;quot;Image:Eb2 container.png&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Class diagram of the container classes in EiffelBase2 library.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14077</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14077"/>
				<updated>2011-03-21T13:26:12Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library, which has for many years played a central role in Eiffel development.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
The latest version of the EiffelBase2 source code is available in the repository: [https://svn.origo.ethz.ch/eiffelbase2/trunk/ https://svn.origo.ethz.ch/eiffelbase2/trunk/]&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Complete specifications. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
On the top level EiffelBase2 differentiates between ''containers'' and interfaces to access elements of containers, called ''accessors''. A container is a finite storage of values. Accessors are either ''maps'' (accessing elements by a unique key) or ''streams'' (linear access). An observer is not necessarily bound to a container, e.g. &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; stream observes an infinite sequence of pseudo-random numbers. Streams that traverse containers are called ''iterators''.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies. The first one is a hierarchy of containers and maps. All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity. &lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
The second one is a hierarchy of streams and iterators.&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence is a model for a stack or a queue. A pair consisting of a sequence and an integer is a model for a list with an internal cursor.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
feature -- Access&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Cursor position&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of list elements&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; consisting of two components: a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of the regular features in their terms. For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. Definitions of zero-argument queries, as usual, can be moved to the class invariant. For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments. If a model query is not mentioned in the postcondition of a command, it is equivalent to stating that it's not modified. &lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is cursor off all elements?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Element change&lt;br /&gt;
    put_right (v: G)&lt;br /&gt;
            -- Put `v' to the right of the cursor&lt;br /&gt;
        require&lt;br /&gt;
            not_after: not after&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            sequence_effect: sequence |=| old (sequence.front (index).extended (v) + sequence.tail (index + 1))&lt;br /&gt;
            index_effect: index = old index&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, suppose that &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; inherits directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;, whose model is a bag:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain = sequence.range&lt;br /&gt;
    bag_definition: bag.domain.for all (agent (x: G): BOOLEAN&lt;br /&gt;
        do Result := bag [x] = sequence.occurrences (x) end)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new  model query &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is currently being developed as a project at ETH Zurich.&lt;br /&gt;
&lt;br /&gt;
===ToDo list===&lt;br /&gt;
* Add immutable and mutable strings.&lt;br /&gt;
* Make model class implementation more efficient.&lt;br /&gt;
* Add classes and directories.&lt;br /&gt;
* Rewrite loops using the &amp;lt;e&amp;gt;across&amp;lt;/e&amp;gt; where appropriate.&lt;br /&gt;
* Add an iterator over keys for &amp;lt;e&amp;gt;TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Make the library void-safe.&lt;br /&gt;
* Implement more efficient data structures: e.g., tables with fast lookup both ways, heaps, skip lists, treaps, etc.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14075</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14075"/>
				<updated>2011-03-11T12:44:21Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library, which has for many years played a central role in Eiffel development.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
The latest version of the EiffelBase2 source code is available in the repository: [https://svn.origo.ethz.ch/eiffelbase2/trunk/ https://svn.origo.ethz.ch/eiffelbase2/trunk/]&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Complete specifications. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
On the top level EiffelBase2 differentiates between ''containers'' and interfaces to access elements of containers, called ''observers''. A container is a finite storage of values. Observers are either ''maps'' (accessing elements by a unique key) or ''streams'' (linear access). An observer is not necessarily bound to a container, e.g. &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; stream observes an infinite sequence of pseudo-random numbers. Streams that traverse containers are called ''iterators''.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies. The first one is a hierarchy of containers and maps. All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity. &lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
The second one is a hierarchy of streams and iterators.&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence is a model for a stack or a queue. A pair consisting of a sequence and an integer is a model for a list with an internal cursor.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
feature -- Access&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Cursor position&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of list elements&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; consisting of two components: a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of the regular features in their terms. For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. Definitions of zero-argument queries, as usual, can be moved to the class invariant. For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments. If a model query is not mentioned in the postcondition of a command, it is equivalent to stating that it's not modified. &lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is cursor off all elements?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Element change&lt;br /&gt;
    put_right (v: G)&lt;br /&gt;
            -- Put `v' to the right of the cursor&lt;br /&gt;
        require&lt;br /&gt;
            not_after: not after&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            sequence_effect: sequence |=| old (sequence.front (index).extended (v) + sequence.tail (index + 1))&lt;br /&gt;
            index_effect: index = old index&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, suppose that &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; inherits directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;, whose model is a bag:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain = sequence.range&lt;br /&gt;
    bag_definition: bag.domain.for all (agent (x: G): BOOLEAN&lt;br /&gt;
        do Result := bag [x] = sequence.occurrences (x) end)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new  model query &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2 is currently being developed as a project at ETH Zurich.&lt;br /&gt;
&lt;br /&gt;
===ToDo list===&lt;br /&gt;
* Add immutable and mutable strings.&lt;br /&gt;
* Make model class implementation more efficient.&lt;br /&gt;
* Add classes and directories.&lt;br /&gt;
* Rewrite loops using the &amp;lt;e&amp;gt;across&amp;lt;/e&amp;gt; where appropriate.&lt;br /&gt;
* Add an iterator over keys for &amp;lt;e&amp;gt;TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Make the library void-safe.&lt;br /&gt;
* Implement more efficient data structures: e.g., tables with fast lookup both ways, heaps, skip lists, treaps, etc.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=File:Eb2_iterator.png&amp;diff=14074</id>
		<title>File:Eb2 iterator.png</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=File:Eb2_iterator.png&amp;diff=14074"/>
				<updated>2011-03-10T14:19:30Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: uploaded a new version of &amp;quot;Image:Eb2 iterator.png&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Class diagram of the iterator classes in EiffelBase2 library.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=File:Eb2_container.png&amp;diff=14073</id>
		<title>File:Eb2 container.png</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=File:Eb2_container.png&amp;diff=14073"/>
				<updated>2011-03-10T14:18:24Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: uploaded a new version of &amp;quot;Image:Eb2 container.png&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Class diagram of the container classes in EiffelBase2 library.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14072</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14072"/>
				<updated>2011-03-10T14:16:42Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2, currently under development, is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library (&amp;quot;Classic EiffelBase&amp;quot; in this document), which has for many years played a central role in Eiffel development. &lt;br /&gt;
&lt;br /&gt;
==Design goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Full contracts. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
*As in Classic EiffelBase, application of a systematic classification (a theory) of fundamental data structures.&lt;br /&gt;
&lt;br /&gt;
*Full traversal mechanisms, based on external cursors (with internal cursors also provided when useful).&lt;br /&gt;
&lt;br /&gt;
*Client-interface compatibility with corresponding classes in Classic EiffelBase, whenever it does not conflict with the preceding goals.&lt;br /&gt;
&lt;br /&gt;
==Design overview==&lt;br /&gt;
===Traversal mechanisms and classification criteria===&lt;br /&gt;
A design decision that significantly influenced the architecture of the library is using external iterators to traverse containers as opposed to internal ones available in classic EiffelBase.&lt;br /&gt;
In the design inspired by external iterators we found it natural to separate ''containers'' (with their measurements and modification means) from interfaces to access elements of containers, here called ''observers''.&lt;br /&gt;
&lt;br /&gt;
On the observer side we distinguish ''maps'' (with the defining property &amp;quot;accessing elements by unique keys&amp;quot;) and iterators (providing linear traversal). An observer can be either ''used'' by a container (as a supplier) or ''inherited'' by it. The first case produces an external access mechanism and is useful when multiple instances of an observer for the same container can exist at the same time; the second case results in an internal access mechanism and allows only one instance of an observer per container at a time. In the rest of the library maps are mostly inherited and iterators are mostly used, but this is not enforced by the design. For infinite sequences like &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; it makes sense to ''inherit'' from an iterator, because they cannot have more than one active iterator.&lt;br /&gt;
&lt;br /&gt;
On the other side, a ''container'' is a finite storage of values. Containers are deliberately confined to finite structures and understood real, physical storage. Infinite structures, instead, are usually represented as functions or mechanisms that are external to a program. Most of the time we can only access their elements (not add or remove) and for this purpose we have observers: maps and iterators (the latter in the infinite case are called ''streams'').&lt;br /&gt;
&lt;br /&gt;
Containers may be classified based on different means of modification, but previous experience shows that a complete and clean classification here is impossible (there are too many kinds of modification, basically one per &amp;quot;concrete&amp;quot; data structure). So concrete data structures mostly just inherit directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;. There is one exception: &amp;lt;e&amp;gt;SEQUENCE&amp;lt;/e&amp;gt;, which represents a sequence of values accessible by indices from a continuous interval. It serves as a common ancestor for ARRAY and LIST and factors out their common search and replacement mechanisms.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies (according to connectedness). The first one is a hierarchy of containers and maps. Note: dash-bordered ovals stand for classes that might be included in the library, but are not the first priority of the developers. All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity. &lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
The second one is a hierarchy of streams and iterators.&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
===Comparison criteria===&lt;br /&gt;
Another important design decision for a data structures library is how to represent and modify comparison criteria for container elements.&lt;br /&gt;
Adjustable comparison criterion is used in search operations and to define the uniqueness property in sets and tables (uniqueness of keys).&lt;br /&gt;
# Classic EiffelBase uses the boolean &amp;lt;e&amp;gt;object_comparison&amp;lt;/e&amp;gt; attribute in &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt; for this purpose.&lt;br /&gt;
# Gobo.structures uses another approach: storing equivalence as an object of a specific class, which can be redefined by the user to implement an arbitrary equalivalence relation.&lt;br /&gt;
# A similar approach would be to use agents to store the equalivalence relation (no need to create classes). The downside is that agents do not serialize well.&lt;br /&gt;
# Another approach is to make &amp;lt;e&amp;gt;has (x: G)&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;search (x: G)&amp;lt;/e&amp;gt; always use &amp;lt;e&amp;gt;=&amp;lt;/e&amp;gt;, but also introduce &amp;lt;e&amp;gt;exists (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;satisfy (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt;. This is more flexible (better fits cases when the predicate is not an equivalence), but duplicates the number of search features and doesn't solve the problem with sets.&lt;br /&gt;
&lt;br /&gt;
An additional question (if the comparison criterion is stored in the container) is whether it can be changed during the object's lifetime. A well known practice is that in sets it is not allowed to change if the set is not empty. This gives rise to &amp;lt;e&amp;gt;changeable_comparison_criterion&amp;lt;/e&amp;gt; query in CONTAINER.&lt;br /&gt;
Note that for most set and table implementations (hashed, sorted) the comparison criterion is related to the corresponding hash function, order, etc. and cannot be modified arbitrarily even when the set or table is empty.&lt;br /&gt;
&lt;br /&gt;
The strategy chosen in EiffelBase2 is to treat differently comparison criteria on which a set or a table is based and ones just used for search. For the first the Gobo approach is taken (2 in the list above), because it is more flexible than in EiffelBase, as we can use whatever equivalence relation we want instead of just &amp;lt;e&amp;gt;is_equal&amp;lt;/e&amp;gt; (useful for library classes). Moreover, the equivalence relation is passed as an argument to the creation procedure and cannot be changed afterward. &lt;br /&gt;
&lt;br /&gt;
For search operations the approach 4 is taken, because it doesn't clutter the container state with properties that don't pertain to the container itself, but to specific search operations.&lt;br /&gt;
&lt;br /&gt;
===Indexing===&lt;br /&gt;
The current version of EiffelBase2 is using the same policy for indexing as the one used in the classic EiffelBase: indexing of lists (and iterators) always starts from 1, whereas for arrays the starting index can be set to an arbitrary value. However, during the code review in the Chair of Software Engineering (17.03.2010) is was decided that the possibility to start arrays from an arbitrary index is not crucial and is used very rarely, but complicates the API. Thus it will probably be changed in future so that indices of arrays, like those of other indexed data structures, always start at 1.&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence is a model for a stack or a queue. A pair consisting of a sequence and an integer is a model for a list with an internal cursor.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
feature -- Access&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Cursor position&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of list elements&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; consisting of two components: a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of the regular features in their terms. For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. Definitions of zero-argument queries, as usual, can be moved to the class invariant. For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments. If a model query is not mentioned in the postcondition of a command, it is equivalent to stating that it's not modified. &lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is cursor off all elements?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Element change&lt;br /&gt;
    put_right (v: G)&lt;br /&gt;
            -- Put `v' to the right of the cursor&lt;br /&gt;
        require&lt;br /&gt;
            not_after: not after&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            sequence_effect: sequence |=| old (sequence.front (index).extended (v) + sequence.tail (index + 1))&lt;br /&gt;
            index_effect: index = old index&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, suppose that &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; inherits directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;, whose model is a bag:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain = sequence.range&lt;br /&gt;
    bag_definition: bag.domain.for all (agent (x: G): BOOLEAN&lt;br /&gt;
        do Result := bag [x] = sequence.occurrences (x) end)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new  model query &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
Development of EiffelBase has started as a project at ETH Zurich; see the [http://eiffelbase2.origo.ethz.ch/ project page]. Documentation and other material will soon be transferred to the present page.&lt;br /&gt;
&lt;br /&gt;
===ToDo list===&lt;br /&gt;
Below you can see a list of most important changes planned for EiffelBase2.&lt;br /&gt;
* Add immutable and mutable strings.&lt;br /&gt;
* Make model class implementation more efficient.&lt;br /&gt;
* Add classes and directories.&lt;br /&gt;
* Rewrite loops using the &amp;lt;e&amp;gt;across&amp;lt;/e&amp;gt; where appropriate.&lt;br /&gt;
* Add an iterator over keys for &amp;lt;e&amp;gt;TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Make the library void-safe.&lt;br /&gt;
* Implement more efficient data structures: e.g., tables with fast lookup both ways, heaps, skip lists, treaps, etc.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14012</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14012"/>
				<updated>2010-11-21T13:43:44Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Comparison criteria */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2, currently under development, is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library (&amp;quot;Classic EiffelBase&amp;quot; in this document), which has for many years played a central role in Eiffel development. &lt;br /&gt;
&lt;br /&gt;
==Design goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Full contracts. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
*As in Classic EiffelBase, application of a systematic classification (a theory) of fundamental data structures.&lt;br /&gt;
&lt;br /&gt;
*Full traversal mechanisms, based on external cursors (with internal cursors also provided when useful).&lt;br /&gt;
&lt;br /&gt;
*Client-interface compatibility with corresponding classes in Classic EiffelBase, whenever it does not conflict with the preceding goals.&lt;br /&gt;
&lt;br /&gt;
==Design overview==&lt;br /&gt;
===Traversal mechanisms and classification criteria===&lt;br /&gt;
A design decision that significantly influenced the architecture of the library is using external iterators to traverse containers as opposed to internal ones available in classic EiffelBase.&lt;br /&gt;
In the design inspired by external iterators we found it natural to separate ''containers'' (with their measurements and modification means) from interfaces to access elements of containers, here called ''observers''.&lt;br /&gt;
&lt;br /&gt;
On the observer side we distinguish ''maps'' (with the defining property &amp;quot;accessing elements by unique keys&amp;quot;) and iterators (providing linear traversal). An observer can be either ''used'' by a container (as a supplier) or ''inherited'' by it. The first case produces an external access mechanism and is useful when multiple instances of an observer for the same container can exist at the same time; the second case results in an internal access mechanism and allows only one instance of an observer per container at a time. In the rest of the library maps are mostly inherited and iterators are mostly used, but this is not enforced by the design. For infinite sequences like &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; it makes sense to ''inherit'' from an iterator, because they cannot have more than one active iterator.&lt;br /&gt;
&lt;br /&gt;
On the other side, a ''container'' is a finite storage of values. Containers are deliberately confined to finite structures and understood real, physical storage. Infinite structures, instead, are usually represented as functions or mechanisms that are external to a program. Most of the time we can only access their elements (not add or remove) and for this purpose we have observers: maps and iterators (the latter in the infinite case are called ''streams'').&lt;br /&gt;
&lt;br /&gt;
Containers may be classified based on different means of modification, but previous experience shows that a complete and clean classification here is impossible (there are too many kinds of modification, basically one per &amp;quot;concrete&amp;quot; data structure). So concrete data structures mostly just inherit directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;. There is one exception: &amp;lt;e&amp;gt;SEQUENCE&amp;lt;/e&amp;gt;, which represents a sequence of values accessible by indices from a continuous interval. It serves as a common ancestor for ARRAY and LIST and factors out their common search and replacement mechanisms.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies (according to connectedness). The first one is a hierarchy of containers and maps. Note: dash-bordered ovals stand for classes that might be included in the library, but are not the first priority of the developers. All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity. &lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
The second one is a hierarchy of streams and iterators.&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
===Comparison criteria===&lt;br /&gt;
Another important design decision for a data structures library is how to represent and modify comparison criteria for container elements.&lt;br /&gt;
Adjustable comparison criterion is used in search operations and to define the uniqueness property in sets and tables (uniqueness of keys).&lt;br /&gt;
# Classic EiffelBase uses the boolean &amp;lt;e&amp;gt;object_comparison&amp;lt;/e&amp;gt; attribute in &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt; for this purpose.&lt;br /&gt;
# Gobo.structures uses another approach: storing equivalence as an object of a specific class, which can be redefined by the user to implement an arbitrary equalivalence relation.&lt;br /&gt;
# A similar approach would be to use agents to store the equalivalence relation (no need to create classes). The downside is that agents do not serialize well.&lt;br /&gt;
# Another approach is to make &amp;lt;e&amp;gt;has (x: G)&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;search (x: G)&amp;lt;/e&amp;gt; always use &amp;lt;e&amp;gt;=&amp;lt;/e&amp;gt;, but also introduce &amp;lt;e&amp;gt;exists (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;satisfy (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt;. This is more flexible (better fits cases when the predicate is not an equivalence), but duplicates the number of search features and doesn't solve the problem with sets.&lt;br /&gt;
&lt;br /&gt;
An additional question (if the comparison criterion is stored in the container) is whether it can be changed during the object's lifetime. A well known practice is that in sets it is not allowed to change if the set is not empty. This gives rise to &amp;lt;e&amp;gt;changeable_comparison_criterion&amp;lt;/e&amp;gt; query in CONTAINER.&lt;br /&gt;
Note that for most set and table implementations (hashed, sorted) the comparison criterion is related to the corresponding hash function, order, etc. and cannot be modified arbitrarily even when the set or table is empty.&lt;br /&gt;
&lt;br /&gt;
The strategy chosen in EiffelBase2 is to treat differently comparison criteria on which a set or a table is based and ones just used for search. For the first the Gobo approach is taken (2 in the list above), because it is more flexible than in EiffelBase, as we can use whatever equivalence relation we want instead of just &amp;lt;e&amp;gt;is_equal&amp;lt;/e&amp;gt; (useful for library classes). Moreover, the equivalence relation is passed as an argument to the creation procedure and cannot be changed afterward. &lt;br /&gt;
&lt;br /&gt;
For search operations the approach 4 is taken, because it doesn't clutter the container state with properties that don't pertain to the container itself, but to specific search operations.&lt;br /&gt;
&lt;br /&gt;
===Indexing===&lt;br /&gt;
The current version of EiffelBase2 is using the same policy for indexing as the one used in the classic EiffelBase: indexing of lists (and iterators) always starts from 1, whereas for arrays the starting index can be set to an arbitrary value. However, during the code review in the Chair of Software Engineering (17.03.2010) is was decided that the possibility to start arrays from an arbitrary index is not crucial and is used very rarely, but complicates the API. Thus it will probably be changed in future so that indices of arrays, like those of other indexed data structures, always start at 1.&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence is a model for a stack or a queue. A pair consisting of a sequence and an integer is a model for a list with an internal cursor.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
feature -- Access&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Cursor position&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of list elements&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; consisting of two components: a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of the regular features in their terms. For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. Definitions of zero-argument queries, as usual, can be moved to the class invariant. For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments. If a model query is not mentioned in the postcondition of a command, it is equivalent to stating that it's not modified. &lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is cursor off all elements?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Element change&lt;br /&gt;
    put_right (v: G)&lt;br /&gt;
            -- Put `v' to the right of the cursor&lt;br /&gt;
        require&lt;br /&gt;
            not_after: not after&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            sequence_effect: sequence |=| old (sequence.front (index).extended (v) + sequence.tail (index + 1))&lt;br /&gt;
            index_effect: index = old index&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, suppose that &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; inherits directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;, whose model is a bag:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain = sequence.range&lt;br /&gt;
    bag_definition: bag.domain.for all (agent (x: G): BOOLEAN&lt;br /&gt;
        do Result := bag [x] = sequence.occurrences (x) end)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new  model query &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
Development of EiffelBase has started as a project at ETH Zurich; see the [http://eiffelbase2.origo.ethz.ch/ project page]. Documentation and other material will soon be transferred to the present page.&lt;br /&gt;
&lt;br /&gt;
===ToDo list===&lt;br /&gt;
Below you can see a list of most important changes planned for EiffelBase2.&lt;br /&gt;
* Finish the implementation of the MML library.&lt;br /&gt;
* Rewrite loops using the &amp;lt;e&amp;gt;across&amp;lt;/e&amp;gt; where appropriate.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;STANDARD_INPUT&amp;lt;/e&amp;gt; streams.&lt;br /&gt;
* Add an iterator over keys for &amp;lt;e&amp;gt;TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Make the library void-safe.&lt;br /&gt;
* Implement more efficient data structures: e.g., tables with fast lookup both ways, heaps, skip lists, treaps, etc.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14011</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14011"/>
				<updated>2010-11-21T13:43:09Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Comparison criteria */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2, currently under development, is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library (&amp;quot;Classic EiffelBase&amp;quot; in this document), which has for many years played a central role in Eiffel development. &lt;br /&gt;
&lt;br /&gt;
==Design goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Full contracts. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
*As in Classic EiffelBase, application of a systematic classification (a theory) of fundamental data structures.&lt;br /&gt;
&lt;br /&gt;
*Full traversal mechanisms, based on external cursors (with internal cursors also provided when useful).&lt;br /&gt;
&lt;br /&gt;
*Client-interface compatibility with corresponding classes in Classic EiffelBase, whenever it does not conflict with the preceding goals.&lt;br /&gt;
&lt;br /&gt;
==Design overview==&lt;br /&gt;
===Traversal mechanisms and classification criteria===&lt;br /&gt;
A design decision that significantly influenced the architecture of the library is using external iterators to traverse containers as opposed to internal ones available in classic EiffelBase.&lt;br /&gt;
In the design inspired by external iterators we found it natural to separate ''containers'' (with their measurements and modification means) from interfaces to access elements of containers, here called ''observers''.&lt;br /&gt;
&lt;br /&gt;
On the observer side we distinguish ''maps'' (with the defining property &amp;quot;accessing elements by unique keys&amp;quot;) and iterators (providing linear traversal). An observer can be either ''used'' by a container (as a supplier) or ''inherited'' by it. The first case produces an external access mechanism and is useful when multiple instances of an observer for the same container can exist at the same time; the second case results in an internal access mechanism and allows only one instance of an observer per container at a time. In the rest of the library maps are mostly inherited and iterators are mostly used, but this is not enforced by the design. For infinite sequences like &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; it makes sense to ''inherit'' from an iterator, because they cannot have more than one active iterator.&lt;br /&gt;
&lt;br /&gt;
On the other side, a ''container'' is a finite storage of values. Containers are deliberately confined to finite structures and understood real, physical storage. Infinite structures, instead, are usually represented as functions or mechanisms that are external to a program. Most of the time we can only access their elements (not add or remove) and for this purpose we have observers: maps and iterators (the latter in the infinite case are called ''streams'').&lt;br /&gt;
&lt;br /&gt;
Containers may be classified based on different means of modification, but previous experience shows that a complete and clean classification here is impossible (there are too many kinds of modification, basically one per &amp;quot;concrete&amp;quot; data structure). So concrete data structures mostly just inherit directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;. There is one exception: &amp;lt;e&amp;gt;SEQUENCE&amp;lt;/e&amp;gt;, which represents a sequence of values accessible by indices from a continuous interval. It serves as a common ancestor for ARRAY and LIST and factors out their common search and replacement mechanisms.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies (according to connectedness). The first one is a hierarchy of containers and maps. Note: dash-bordered ovals stand for classes that might be included in the library, but are not the first priority of the developers. All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity. &lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
The second one is a hierarchy of streams and iterators.&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
===Comparison criteria===&lt;br /&gt;
Another important design decision for a data structures library is how to represent and modify comparison criteria for container elements.&lt;br /&gt;
Adjustable comparison criterion is used in search operations and to define the uniqueness property in sets and tables (uniqueness of keys).&lt;br /&gt;
# Classic EiffelBase uses the boolean &amp;lt;e&amp;gt;object_comparison&amp;lt;/e&amp;gt; attribute in &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt; for this purpose.&lt;br /&gt;
# Gobo.structures uses another approach: storing equivalence as an object of a specific class, which can be redefined by the user to implement an arbitrary equalivalence relation.&lt;br /&gt;
# A similar approach would be to use agents to store the equalivalence relation (no need to create classes). The downside is that agents do not serialize well.&lt;br /&gt;
# Another approach is to make &amp;lt;e&amp;gt;has (x: G)&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;search (x: G)&amp;lt;/e&amp;gt; always use &amp;lt;e&amp;gt;=&amp;lt;/e&amp;gt;, but also introduce &amp;lt;e&amp;gt;exists (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;satisfy (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt;. This is more flexible (better fits cases when the predicate is not an equivalence), but duplicates the number of search features and doesn't solve the problem with sets.&lt;br /&gt;
&lt;br /&gt;
An additional question (if the comparison criterion is stored in the container) is whether it can be changed during the object's lifetime. A well known practice is that in sets it is not allowed to change if the set is not empty. This gives rise to &amp;lt;e&amp;gt;changeable_comparison_criterion&amp;lt;/e&amp;gt; query in CONTAINER.&lt;br /&gt;
Note that for most set and table implementations (hashed, sorted) the comparison criterion is related the corresponding hash function, order, etc. and cannot be modified arbitrarily even when the set or table is empty.&lt;br /&gt;
&lt;br /&gt;
The strategy chosen in EiffelBase2 is to treat differently comparison criteria on which a set or a table is based and ones just used for search. For the first the Gobo approach is taken (2 in the list above), because it is more flexible than in EiffelBase, as we can use whatever equivalence relation we want instead of just &amp;lt;e&amp;gt;is_equal&amp;lt;/e&amp;gt; (useful for library classes). Moreover, the equivalence relation is passed as an argument to the creation procedure and cannot be changed afterward. &lt;br /&gt;
&lt;br /&gt;
For search operations the approach 4 is taken, because it doesn't clutter the container state with properties that don't pertain to the container itself, but to specific search operations.&lt;br /&gt;
&lt;br /&gt;
===Indexing===&lt;br /&gt;
The current version of EiffelBase2 is using the same policy for indexing as the one used in the classic EiffelBase: indexing of lists (and iterators) always starts from 1, whereas for arrays the starting index can be set to an arbitrary value. However, during the code review in the Chair of Software Engineering (17.03.2010) is was decided that the possibility to start arrays from an arbitrary index is not crucial and is used very rarely, but complicates the API. Thus it will probably be changed in future so that indices of arrays, like those of other indexed data structures, always start at 1.&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence is a model for a stack or a queue. A pair consisting of a sequence and an integer is a model for a list with an internal cursor.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
feature -- Access&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Cursor position&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of list elements&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; consisting of two components: a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of the regular features in their terms. For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. Definitions of zero-argument queries, as usual, can be moved to the class invariant. For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments. If a model query is not mentioned in the postcondition of a command, it is equivalent to stating that it's not modified. &lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is cursor off all elements?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Element change&lt;br /&gt;
    put_right (v: G)&lt;br /&gt;
            -- Put `v' to the right of the cursor&lt;br /&gt;
        require&lt;br /&gt;
            not_after: not after&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            sequence_effect: sequence |=| old (sequence.front (index).extended (v) + sequence.tail (index + 1))&lt;br /&gt;
            index_effect: index = old index&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, suppose that &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; inherits directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;, whose model is a bag:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain = sequence.range&lt;br /&gt;
    bag_definition: bag.domain.for all (agent (x: G): BOOLEAN&lt;br /&gt;
        do Result := bag [x] = sequence.occurrences (x) end)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new  model query &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
Development of EiffelBase has started as a project at ETH Zurich; see the [http://eiffelbase2.origo.ethz.ch/ project page]. Documentation and other material will soon be transferred to the present page.&lt;br /&gt;
&lt;br /&gt;
===ToDo list===&lt;br /&gt;
Below you can see a list of most important changes planned for EiffelBase2.&lt;br /&gt;
* Finish the implementation of the MML library.&lt;br /&gt;
* Rewrite loops using the &amp;lt;e&amp;gt;across&amp;lt;/e&amp;gt; where appropriate.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;STANDARD_INPUT&amp;lt;/e&amp;gt; streams.&lt;br /&gt;
* Add an iterator over keys for &amp;lt;e&amp;gt;TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Make the library void-safe.&lt;br /&gt;
* Implement more efficient data structures: e.g., tables with fast lookup both ways, heaps, skip lists, treaps, etc.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14010</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=14010"/>
				<updated>2010-11-21T13:31:36Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* ToDo list */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2, currently under development, is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library (&amp;quot;Classic EiffelBase&amp;quot; in this document), which has for many years played a central role in Eiffel development. &lt;br /&gt;
&lt;br /&gt;
==Design goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Full contracts. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
*As in Classic EiffelBase, application of a systematic classification (a theory) of fundamental data structures.&lt;br /&gt;
&lt;br /&gt;
*Full traversal mechanisms, based on external cursors (with internal cursors also provided when useful).&lt;br /&gt;
&lt;br /&gt;
*Client-interface compatibility with corresponding classes in Classic EiffelBase, whenever it does not conflict with the preceding goals.&lt;br /&gt;
&lt;br /&gt;
==Design overview==&lt;br /&gt;
===Traversal mechanisms and classification criteria===&lt;br /&gt;
A design decision that significantly influenced the architecture of the library is using external iterators to traverse containers as opposed to internal ones available in classic EiffelBase.&lt;br /&gt;
In the design inspired by external iterators we found it natural to separate ''containers'' (with their measurements and modification means) from interfaces to access elements of containers, here called ''observers''.&lt;br /&gt;
&lt;br /&gt;
On the observer side we distinguish ''maps'' (with the defining property &amp;quot;accessing elements by unique keys&amp;quot;) and iterators (providing linear traversal). An observer can be either ''used'' by a container (as a supplier) or ''inherited'' by it. The first case produces an external access mechanism and is useful when multiple instances of an observer for the same container can exist at the same time; the second case results in an internal access mechanism and allows only one instance of an observer per container at a time. In the rest of the library maps are mostly inherited and iterators are mostly used, but this is not enforced by the design. For infinite sequences like &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; it makes sense to ''inherit'' from an iterator, because they cannot have more than one active iterator.&lt;br /&gt;
&lt;br /&gt;
On the other side, a ''container'' is a finite storage of values. Containers are deliberately confined to finite structures and understood real, physical storage. Infinite structures, instead, are usually represented as functions or mechanisms that are external to a program. Most of the time we can only access their elements (not add or remove) and for this purpose we have observers: maps and iterators (the latter in the infinite case are called ''streams'').&lt;br /&gt;
&lt;br /&gt;
Containers may be classified based on different means of modification, but previous experience shows that a complete and clean classification here is impossible (there are too many kinds of modification, basically one per &amp;quot;concrete&amp;quot; data structure). So concrete data structures mostly just inherit directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;. There is one exception: &amp;lt;e&amp;gt;SEQUENCE&amp;lt;/e&amp;gt;, which represents a sequence of values accessible by indices from a continuous interval. It serves as a common ancestor for ARRAY and LIST and factors out their common search and replacement mechanisms.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies (according to connectedness). The first one is a hierarchy of containers and maps. Note: dash-bordered ovals stand for classes that might be included in the library, but are not the first priority of the developers. All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity. &lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
The second one is a hierarchy of streams and iterators.&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
===Comparison criteria===&lt;br /&gt;
Another important design decision for a data structures library is how to represent and modify comparison criteria for container elements.&lt;br /&gt;
Adjustable comparison criterion is used in search operations and to define the uniqueness property in sets and tables (uniqueness of keys).&lt;br /&gt;
# Classic EiffelBase uses the boolean &amp;lt;e&amp;gt;object_comparison&amp;lt;/e&amp;gt; attribute in &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt; for this purpose.&lt;br /&gt;
# Gobo.structures uses another approach: storing equivalence as an object of a specific class, which can be redefined by the user to implement an arbitrary equalivalence relation.&lt;br /&gt;
# A similar approach would be to use agents to store the equalivalence relation (no need to create classes). The downside is that agents do not serialize well.&lt;br /&gt;
# Another approach is to make &amp;lt;e&amp;gt;has (x: G)&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;search (x: G)&amp;lt;/e&amp;gt; always use &amp;lt;e&amp;gt;=&amp;lt;/e&amp;gt;, but also introduce &amp;lt;e&amp;gt;exists (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;satisfy (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt;. This is more flexible (better fits cases when the predicate is not an equivalence), but duplicates the number of search features and doesn't solve the problem with sets.&lt;br /&gt;
&lt;br /&gt;
An additional question (if the comparison criterion is stored in the container) is whether it can be changed during the object's lifetime. A well known practice is that in sets it is not allowed to change if the set is not empty. This gives rise to &amp;lt;e&amp;gt;changeable_comparison_criterion&amp;lt;/e&amp;gt; query in CONTAINER.&lt;br /&gt;
Note that for most set and table implementations (hashed, sorted) the comparison criterion is defined by the corresponding hash function, order, etc. and cannot be modified arbitrarily even when the set or table is empty.&lt;br /&gt;
&lt;br /&gt;
The strategy chosen in EiffelBase2 is to treat differently comparison criteria on which a set or a table is based and ones just used for search. For the first the Gobo approach is taken (2 in the list above), because it is more flexible than in EiffelBase, as we can use whatever equivalence relation we want instead of just &amp;lt;e&amp;gt;is_equal&amp;lt;/e&amp;gt; (useful for library classes). Moreover, the equivalence relation is passed as an argument to the creation procedure and cannot be changed afterward. &lt;br /&gt;
&lt;br /&gt;
For search operations the approach 4 is taken, because it doesn't clutter the container state with properties that don't pertain to the container itself, but to specific search operations.&lt;br /&gt;
&lt;br /&gt;
===Indexing===&lt;br /&gt;
The current version of EiffelBase2 is using the same policy for indexing as the one used in the classic EiffelBase: indexing of lists (and iterators) always starts from 1, whereas for arrays the starting index can be set to an arbitrary value. However, during the code review in the Chair of Software Engineering (17.03.2010) is was decided that the possibility to start arrays from an arbitrary index is not crucial and is used very rarely, but complicates the API. Thus it will probably be changed in future so that indices of arrays, like those of other indexed data structures, always start at 1.&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence is a model for a stack or a queue. A pair consisting of a sequence and an integer is a model for a list with an internal cursor.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
feature -- Access&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Cursor position&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of list elements&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; consisting of two components: a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of the regular features in their terms. For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. Definitions of zero-argument queries, as usual, can be moved to the class invariant. For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments. If a model query is not mentioned in the postcondition of a command, it is equivalent to stating that it's not modified. &lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is cursor off all elements?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Element change&lt;br /&gt;
    put_right (v: G)&lt;br /&gt;
            -- Put `v' to the right of the cursor&lt;br /&gt;
        require&lt;br /&gt;
            not_after: not after&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            sequence_effect: sequence |=| old (sequence.front (index).extended (v) + sequence.tail (index + 1))&lt;br /&gt;
            index_effect: index = old index&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, suppose that &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; inherits directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;, whose model is a bag:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain = sequence.range&lt;br /&gt;
    bag_definition: bag.domain.for all (agent (x: G): BOOLEAN&lt;br /&gt;
        do Result := bag [x] = sequence.occurrences (x) end)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new  model query &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
Development of EiffelBase has started as a project at ETH Zurich; see the [http://eiffelbase2.origo.ethz.ch/ project page]. Documentation and other material will soon be transferred to the present page.&lt;br /&gt;
&lt;br /&gt;
===ToDo list===&lt;br /&gt;
Below you can see a list of most important changes planned for EiffelBase2.&lt;br /&gt;
* Finish the implementation of the MML library.&lt;br /&gt;
* Rewrite loops using the &amp;lt;e&amp;gt;across&amp;lt;/e&amp;gt; where appropriate.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;STANDARD_INPUT&amp;lt;/e&amp;gt; streams.&lt;br /&gt;
* Add an iterator over keys for &amp;lt;e&amp;gt;TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Make the library void-safe.&lt;br /&gt;
* Implement more efficient data structures: e.g., tables with fast lookup both ways, heaps, skip lists, treaps, etc.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13990</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13990"/>
				<updated>2010-09-16T15:18:28Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* ToDo list */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2, currently under development, is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library (&amp;quot;Classic EiffelBase&amp;quot; in this document), which has for many years played a central role in Eiffel development. &lt;br /&gt;
&lt;br /&gt;
==Design goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Full contracts. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
*As in Classic EiffelBase, application of a systematic classification (a theory) of fundamental data structures.&lt;br /&gt;
&lt;br /&gt;
*Full traversal mechanisms, based on external cursors (with internal cursors also provided when useful).&lt;br /&gt;
&lt;br /&gt;
*Client-interface compatibility with corresponding classes in Classic EiffelBase, whenever it does not conflict with the preceding goals.&lt;br /&gt;
&lt;br /&gt;
==Design overview==&lt;br /&gt;
===Traversal mechanisms and classification criteria===&lt;br /&gt;
A design decision that significantly influenced the architecture of the library is using external iterators to traverse containers as opposed to internal ones available in classic EiffelBase.&lt;br /&gt;
In the design inspired by external iterators we found it natural to separate ''containers'' (with their measurements and modification means) from interfaces to access elements of containers, here called ''observers''.&lt;br /&gt;
&lt;br /&gt;
On the observer side we distinguish ''maps'' (with the defining property &amp;quot;accessing elements by unique keys&amp;quot;) and iterators (providing linear traversal). An observer can be either ''used'' by a container (as a supplier) or ''inherited'' by it. The first case produces an external access mechanism and is useful when multiple instances of an observer for the same container can exist at the same time; the second case results in an internal access mechanism and allows only one instance of an observer per container at a time. In the rest of the library maps are mostly inherited and iterators are mostly used, but this is not enforced by the design. For infinite sequences like &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; it makes sense to ''inherit'' from an iterator, because they cannot have more than one active iterator.&lt;br /&gt;
&lt;br /&gt;
On the other side, a ''container'' is a finite storage of values. Containers are deliberately confined to finite structures and understood real, physical storage. Infinite structures, instead, are usually represented as functions or mechanisms that are external to a program. Most of the time we can only access their elements (not add or remove) and for this purpose we have observers: maps and iterators (the latter in the infinite case are called ''streams'').&lt;br /&gt;
&lt;br /&gt;
Containers may be classified based on different means of modification, but previous experience shows that a complete and clean classification here is impossible (there are too many kinds of modification, basically one per &amp;quot;concrete&amp;quot; data structure). So concrete data structures mostly just inherit directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;. There is one exception: &amp;lt;e&amp;gt;SEQUENCE&amp;lt;/e&amp;gt;, which represents a sequence of values accessible by indices from a continuous interval. It serves as a common ancestor for ARRAY and LIST and factors out their common search and replacement mechanisms.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies (according to connectedness). The first one is a hierarchy of containers and maps. Note: dash-bordered ovals stand for classes that might be included in the library, but are not the first priority of the developers. All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity. &lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
The second one is a hierarchy of streams and iterators.&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
===Comparison criteria===&lt;br /&gt;
Another important design decision for a data structures library is how to represent and modify comparison criteria for container elements.&lt;br /&gt;
Adjustable comparison criterion is used in search operations and to define the uniqueness property in sets and tables (uniqueness of keys).&lt;br /&gt;
# Classic EiffelBase uses the boolean &amp;lt;e&amp;gt;object_comparison&amp;lt;/e&amp;gt; attribute in &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt; for this purpose.&lt;br /&gt;
# Gobo.structures uses another approach: storing equivalence as an object of a specific class, which can be redefined by the user to implement an arbitrary equalivalence relation.&lt;br /&gt;
# A similar approach would be to use agents to store the equalivalence relation (no need to create classes). The downside is that agents do not serialize well.&lt;br /&gt;
# Another approach is to make &amp;lt;e&amp;gt;has (x: G)&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;search (x: G)&amp;lt;/e&amp;gt; always use &amp;lt;e&amp;gt;=&amp;lt;/e&amp;gt;, but also introduce &amp;lt;e&amp;gt;exists (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;satisfy (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt;. This is more flexible (better fits cases when the predicate is not an equivalence), but duplicates the number of search features and doesn't solve the problem with sets.&lt;br /&gt;
&lt;br /&gt;
An additional question (if the comparison criterion is stored in the container) is whether it can be changed during the object's lifetime. A well known practice is that in sets it is not allowed to change if the set is not empty. This gives rise to &amp;lt;e&amp;gt;changeable_comparison_criterion&amp;lt;/e&amp;gt; query in CONTAINER.&lt;br /&gt;
Note that for most set and table implementations (hashed, sorted) the comparison criterion is defined by the corresponding hash function, order, etc. and cannot be modified arbitrarily even when the set or table is empty.&lt;br /&gt;
&lt;br /&gt;
The strategy chosen in EiffelBase2 is to treat differently comparison criteria on which a set or a table is based and ones just used for search. For the first the Gobo approach is taken (2 in the list above), because it is more flexible than in EiffelBase, as we can use whatever equivalence relation we want instead of just &amp;lt;e&amp;gt;is_equal&amp;lt;/e&amp;gt; (useful for library classes). Moreover, the equivalence relation is passed as an argument to the creation procedure and cannot be changed afterward. &lt;br /&gt;
&lt;br /&gt;
For search operations the approach 4 is taken, because it doesn't clutter the container state with properties that don't pertain to the container itself, but to specific search operations.&lt;br /&gt;
&lt;br /&gt;
===Indexing===&lt;br /&gt;
The current version of EiffelBase2 is using the same policy for indexing as the one used in the classic EiffelBase: indexing of lists (and iterators) always starts from 1, whereas for arrays the starting index can be set to an arbitrary value. However, during the code review in the Chair of Software Engineering (17.03.2010) is was decided that the possibility to start arrays from an arbitrary index is not crucial and is used very rarely, but complicates the API. Thus it will probably be changed in future so that indices of arrays, like those of other indexed data structures, always start at 1.&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence is a model for a stack or a queue. A pair consisting of a sequence and an integer is a model for a list with an internal cursor.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
feature -- Access&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Cursor position&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of list elements&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; consisting of two components: a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of the regular features in their terms. For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. Definitions of zero-argument queries, as usual, can be moved to the class invariant. For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments. If a model query is not mentioned in the postcondition of a command, it is equivalent to stating that it's not modified. &lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is cursor off all elements?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Element change&lt;br /&gt;
    put_right (v: G)&lt;br /&gt;
            -- Put `v' to the right of the cursor&lt;br /&gt;
        require&lt;br /&gt;
            not_after: not after&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            sequence_effect: sequence |=| old (sequence.front (index).extended (v) + sequence.tail (index + 1))&lt;br /&gt;
            index_effect: index = old index&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, suppose that &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; inherits directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;, whose model is a bag:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain = sequence.range&lt;br /&gt;
    bag_definition: bag.domain.for all (agent (x: G): BOOLEAN&lt;br /&gt;
        do Result := bag [x] = sequence.occurrences (x) end)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new  model query &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
Development of EiffelBase has started as a project at ETH Zurich; see the [http://eiffelbase2.origo.ethz.ch/ project page]. Documentation and other material will soon be transferred to the present page.&lt;br /&gt;
&lt;br /&gt;
===ToDo list===&lt;br /&gt;
Below you can see a list of most important changes planned for EiffelBase2.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;PREORDER_ITERATOR&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;POSTORDER_ITERATOR&amp;lt;/e&amp;gt; to traverse binary trees in pre- and postorder.&lt;br /&gt;
* Finish the implementation of the MML library.&lt;br /&gt;
* Rewrite loops using the &amp;lt;e&amp;gt;across&amp;lt;/e&amp;gt; where appropriate.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;STANDARD_INPUT&amp;lt;/e&amp;gt; streams.&lt;br /&gt;
* Add an iterator over keys for &amp;lt;e&amp;gt;TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Make the library void-safe.&lt;br /&gt;
* Implement more efficient data structures: e.g., tables with fast lookup both ways, heaps, skip lists, treaps, etc.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13989</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13989"/>
				<updated>2010-09-16T15:17:48Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* ToDo list */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2, currently under development, is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library (&amp;quot;Classic EiffelBase&amp;quot; in this document), which has for many years played a central role in Eiffel development. &lt;br /&gt;
&lt;br /&gt;
==Design goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Full contracts. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
*As in Classic EiffelBase, application of a systematic classification (a theory) of fundamental data structures.&lt;br /&gt;
&lt;br /&gt;
*Full traversal mechanisms, based on external cursors (with internal cursors also provided when useful).&lt;br /&gt;
&lt;br /&gt;
*Client-interface compatibility with corresponding classes in Classic EiffelBase, whenever it does not conflict with the preceding goals.&lt;br /&gt;
&lt;br /&gt;
==Design overview==&lt;br /&gt;
===Traversal mechanisms and classification criteria===&lt;br /&gt;
A design decision that significantly influenced the architecture of the library is using external iterators to traverse containers as opposed to internal ones available in classic EiffelBase.&lt;br /&gt;
In the design inspired by external iterators we found it natural to separate ''containers'' (with their measurements and modification means) from interfaces to access elements of containers, here called ''observers''.&lt;br /&gt;
&lt;br /&gt;
On the observer side we distinguish ''maps'' (with the defining property &amp;quot;accessing elements by unique keys&amp;quot;) and iterators (providing linear traversal). An observer can be either ''used'' by a container (as a supplier) or ''inherited'' by it. The first case produces an external access mechanism and is useful when multiple instances of an observer for the same container can exist at the same time; the second case results in an internal access mechanism and allows only one instance of an observer per container at a time. In the rest of the library maps are mostly inherited and iterators are mostly used, but this is not enforced by the design. For infinite sequences like &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; it makes sense to ''inherit'' from an iterator, because they cannot have more than one active iterator.&lt;br /&gt;
&lt;br /&gt;
On the other side, a ''container'' is a finite storage of values. Containers are deliberately confined to finite structures and understood real, physical storage. Infinite structures, instead, are usually represented as functions or mechanisms that are external to a program. Most of the time we can only access their elements (not add or remove) and for this purpose we have observers: maps and iterators (the latter in the infinite case are called ''streams'').&lt;br /&gt;
&lt;br /&gt;
Containers may be classified based on different means of modification, but previous experience shows that a complete and clean classification here is impossible (there are too many kinds of modification, basically one per &amp;quot;concrete&amp;quot; data structure). So concrete data structures mostly just inherit directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;. There is one exception: &amp;lt;e&amp;gt;SEQUENCE&amp;lt;/e&amp;gt;, which represents a sequence of values accessible by indices from a continuous interval. It serves as a common ancestor for ARRAY and LIST and factors out their common search and replacement mechanisms.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies (according to connectedness). The first one is a hierarchy of containers and maps. Note: dash-bordered ovals stand for classes that might be included in the library, but are not the first priority of the developers. All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity. &lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
The second one is a hierarchy of streams and iterators.&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
===Comparison criteria===&lt;br /&gt;
Another important design decision for a data structures library is how to represent and modify comparison criteria for container elements.&lt;br /&gt;
Adjustable comparison criterion is used in search operations and to define the uniqueness property in sets and tables (uniqueness of keys).&lt;br /&gt;
# Classic EiffelBase uses the boolean &amp;lt;e&amp;gt;object_comparison&amp;lt;/e&amp;gt; attribute in &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt; for this purpose.&lt;br /&gt;
# Gobo.structures uses another approach: storing equivalence as an object of a specific class, which can be redefined by the user to implement an arbitrary equalivalence relation.&lt;br /&gt;
# A similar approach would be to use agents to store the equalivalence relation (no need to create classes). The downside is that agents do not serialize well.&lt;br /&gt;
# Another approach is to make &amp;lt;e&amp;gt;has (x: G)&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;search (x: G)&amp;lt;/e&amp;gt; always use &amp;lt;e&amp;gt;=&amp;lt;/e&amp;gt;, but also introduce &amp;lt;e&amp;gt;exists (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;satisfy (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt;. This is more flexible (better fits cases when the predicate is not an equivalence), but duplicates the number of search features and doesn't solve the problem with sets.&lt;br /&gt;
&lt;br /&gt;
An additional question (if the comparison criterion is stored in the container) is whether it can be changed during the object's lifetime. A well known practice is that in sets it is not allowed to change if the set is not empty. This gives rise to &amp;lt;e&amp;gt;changeable_comparison_criterion&amp;lt;/e&amp;gt; query in CONTAINER.&lt;br /&gt;
Note that for most set and table implementations (hashed, sorted) the comparison criterion is defined by the corresponding hash function, order, etc. and cannot be modified arbitrarily even when the set or table is empty.&lt;br /&gt;
&lt;br /&gt;
The strategy chosen in EiffelBase2 is to treat differently comparison criteria on which a set or a table is based and ones just used for search. For the first the Gobo approach is taken (2 in the list above), because it is more flexible than in EiffelBase, as we can use whatever equivalence relation we want instead of just &amp;lt;e&amp;gt;is_equal&amp;lt;/e&amp;gt; (useful for library classes). Moreover, the equivalence relation is passed as an argument to the creation procedure and cannot be changed afterward. &lt;br /&gt;
&lt;br /&gt;
For search operations the approach 4 is taken, because it doesn't clutter the container state with properties that don't pertain to the container itself, but to specific search operations.&lt;br /&gt;
&lt;br /&gt;
===Indexing===&lt;br /&gt;
The current version of EiffelBase2 is using the same policy for indexing as the one used in the classic EiffelBase: indexing of lists (and iterators) always starts from 1, whereas for arrays the starting index can be set to an arbitrary value. However, during the code review in the Chair of Software Engineering (17.03.2010) is was decided that the possibility to start arrays from an arbitrary index is not crucial and is used very rarely, but complicates the API. Thus it will probably be changed in future so that indices of arrays, like those of other indexed data structures, always start at 1.&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence is a model for a stack or a queue. A pair consisting of a sequence and an integer is a model for a list with an internal cursor.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
feature -- Access&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Cursor position&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of list elements&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; consisting of two components: a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of the regular features in their terms. For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. Definitions of zero-argument queries, as usual, can be moved to the class invariant. For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments. If a model query is not mentioned in the postcondition of a command, it is equivalent to stating that it's not modified. &lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is cursor off all elements?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Element change&lt;br /&gt;
    put_right (v: G)&lt;br /&gt;
            -- Put `v' to the right of the cursor&lt;br /&gt;
        require&lt;br /&gt;
            not_after: not after&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            sequence_effect: sequence |=| old (sequence.front (index).extended (v) + sequence.tail (index + 1))&lt;br /&gt;
            index_effect: index = old index&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, suppose that &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; inherits directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;, whose model is a bag:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain = sequence.range&lt;br /&gt;
    bag_definition: bag.domain.for all (agent (x: G): BOOLEAN&lt;br /&gt;
        do Result := bag [x] = sequence.occurrences (x) end)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new  model query &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
Development of EiffelBase has started as a project at ETH Zurich; see the [http://eiffelbase2.origo.ethz.ch/ project page]. Documentation and other material will soon be transferred to the present page.&lt;br /&gt;
&lt;br /&gt;
===ToDo list===&lt;br /&gt;
Below you can see a list of most important changes planned for EiffelBase2.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;PREORDER_ITERATOR&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;POSTORDER_ITERATOR&amp;lt;/e&amp;gt; to traverse binaries in pre- and postorder.&lt;br /&gt;
* Finish the implementation of the MML library.&lt;br /&gt;
* Rewrite loops using the &amp;lt;e&amp;gt;across&amp;lt;/e&amp;gt; where appropriate.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;STANDARD_INPUT&amp;lt;/e&amp;gt; streams.&lt;br /&gt;
* Add an iterator over keys for &amp;lt;e&amp;gt;TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Make the library void-safe.&lt;br /&gt;
* Implement more efficient data structures: e.g., tables with fast lookup both ways, heaps, skip lists, treaps, etc.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13936</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13936"/>
				<updated>2010-07-29T12:24:29Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* ToDo list */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2, currently under development, is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library (&amp;quot;Classic EiffelBase&amp;quot; in this document), which has for many years played a central role in Eiffel development. &lt;br /&gt;
&lt;br /&gt;
==Design goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Full contracts. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
*As in Classic EiffelBase, application of a systematic classification (a theory) of fundamental data structures.&lt;br /&gt;
&lt;br /&gt;
*Full traversal mechanisms, based on external cursors (with internal cursors also provided when useful).&lt;br /&gt;
&lt;br /&gt;
*Client-interface compatibility with corresponding classes in Classic EiffelBase, whenever it does not conflict with the preceding goals.&lt;br /&gt;
&lt;br /&gt;
==Design overview==&lt;br /&gt;
===Traversal mechanisms and classification criteria===&lt;br /&gt;
A design decision that significantly influenced the architecture of the library is using external iterators to traverse containers as opposed to internal ones available in classic EiffelBase.&lt;br /&gt;
In the design inspired by external iterators we found it natural to separate ''containers'' (with their measurements and modification means) from interfaces to access elements of containers, here called ''observers''.&lt;br /&gt;
&lt;br /&gt;
On the observer side we distinguish ''maps'' (with the defining property &amp;quot;accessing elements by unique keys&amp;quot;) and iterators (providing linear traversal). An observer can be either ''used'' by a container (as a supplier) or ''inherited'' by it. The first case produces an external access mechanism and is useful when multiple instances of an observer for the same container can exist at the same time; the second case results in an internal access mechanism and allows only one instance of an observer per container at a time. In the rest of the library maps are mostly inherited and iterators are mostly used, but this is not enforced by the design. For infinite sequences like &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; it makes sense to ''inherit'' from an iterator, because they cannot have more than one active iterator.&lt;br /&gt;
&lt;br /&gt;
On the other side, a ''container'' is a finite storage of values. Containers are deliberately confined to finite structures and understood real, physical storage. Infinite structures, instead, are usually represented as functions or mechanisms that are external to a program. Most of the time we can only access their elements (not add or remove) and for this purpose we have observers: maps and iterators (the latter in the infinite case are called ''streams'').&lt;br /&gt;
&lt;br /&gt;
Containers may be classified based on different means of modification, but previous experience shows that a complete and clean classification here is impossible (there are too many kinds of modification, basically one per &amp;quot;concrete&amp;quot; data structure). So concrete data structures mostly just inherit directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;. There is one exception: &amp;lt;e&amp;gt;SEQUENCE&amp;lt;/e&amp;gt;, which represents a sequence of values accessible by indices from a continuous interval. It serves as a common ancestor for ARRAY and LIST and factors out their common search and replacement mechanisms.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies (according to connectedness). The first one is a hierarchy of containers and maps. Note: dash-bordered ovals stand for classes that might be included in the library, but are not the first priority of the developers. All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity. &lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
The second one is a hierarchy of streams and iterators.&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
===Comparison criteria===&lt;br /&gt;
Another important design decision for a data structures library is how to represent and modify comparison criteria for container elements.&lt;br /&gt;
Adjustable comparison criterion is used in search operations and to define the uniqueness property in sets and tables (uniqueness of keys).&lt;br /&gt;
# Classic EiffelBase uses the boolean &amp;lt;e&amp;gt;object_comparison&amp;lt;/e&amp;gt; attribute in &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt; for this purpose.&lt;br /&gt;
# Gobo.structures uses another approach: storing equivalence as an object of a specific class, which can be redefined by the user to implement an arbitrary equalivalence relation.&lt;br /&gt;
# A similar approach would be to use agents to store the equalivalence relation (no need to create classes). The downside is that agents do not serialize well.&lt;br /&gt;
# Another approach is to make &amp;lt;e&amp;gt;has (x: G)&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;search (x: G)&amp;lt;/e&amp;gt; always use &amp;lt;e&amp;gt;=&amp;lt;/e&amp;gt;, but also introduce &amp;lt;e&amp;gt;exists (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;satisfy (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt;. This is more flexible (better fits cases when the predicate is not an equivalence), but duplicates the number of search features and doesn't solve the problem with sets.&lt;br /&gt;
&lt;br /&gt;
An additional question (if the comparison criterion is stored in the container) is whether it can be changed during the object's lifetime. A well known practice is that in sets it is not allowed to change if the set is not empty. This gives rise to &amp;lt;e&amp;gt;changeable_comparison_criterion&amp;lt;/e&amp;gt; query in CONTAINER.&lt;br /&gt;
Note that for most set and table implementations (hashed, sorted) the comparison criterion is defined by the corresponding hash function, order, etc. and cannot be modified arbitrarily even when the set or table is empty.&lt;br /&gt;
&lt;br /&gt;
The strategy chosen in EiffelBase2 is to treat differently comparison criteria on which a set or a table is based and ones just used for search. For the first the Gobo approach is taken (2 in the list above), because it is more flexible than in EiffelBase, as we can use whatever equivalence relation we want instead of just &amp;lt;e&amp;gt;is_equal&amp;lt;/e&amp;gt; (useful for library classes). Moreover, the equivalence relation is passed as an argument to the creation procedure and cannot be changed afterward. &lt;br /&gt;
&lt;br /&gt;
For search operations the approach 4 is taken, because it doesn't clutter the container state with properties that don't pertain to the container itself, but to specific search operations.&lt;br /&gt;
&lt;br /&gt;
===Indexing===&lt;br /&gt;
The current version of EiffelBase2 is using the same policy for indexing as the one used in the classic EiffelBase: indexing of lists (and iterators) always starts from 1, whereas for arrays the starting index can be set to an arbitrary value. However, during the code review in the Chair of Software Engineering (17.03.2010) is was decided that the possibility to start arrays from an arbitrary index is not crucial and is used very rarely, but complicates the API. Thus it will probably be changed in future so that indices of arrays, like those of other indexed data structures, always start at 1.&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class defines a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence is a model for a stack or a queue. A pair consisting of a sequence and an integer is a model for a list with an internal cursor.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
feature -- Access&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Cursor position&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of list elements&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; consisting of two components: a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of the regular features in their terms. For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. Definitions of zero-argument queries, as usual, can be moved to the class invariant. For commands we define their effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments. If a model query is not mentioned in the postcondition of a command, it is equivalent to stating that it's not modified. &lt;br /&gt;
&lt;br /&gt;
The model-based contracts approach does not constrain the way in which you write preconditions: it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in the model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is cursor off all elements?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Element change&lt;br /&gt;
    put_right (v: G)&lt;br /&gt;
            -- Put `v' to the right of the cursor&lt;br /&gt;
        require&lt;br /&gt;
            not_after: not after&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            sequence_effect: sequence |=| old (sequence.front (index).extended (v) + sequence.tail (index + 1))&lt;br /&gt;
            index_effect: index = old index&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, suppose that &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; inherits directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;, whose model is a bag:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain = sequence.range&lt;br /&gt;
    bag_definition: bag.domain.for all (agent (x: G): BOOLEAN&lt;br /&gt;
        do Result := bag [x] = sequence.occurrences (x) end)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new  model query &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
Development of EiffelBase has started as a project at ETH Zurich; see the [http://eiffelbase2.origo.ethz.ch/ project page]. Documentation and other material will soon be transferred to the present page.&lt;br /&gt;
&lt;br /&gt;
===ToDo list===&lt;br /&gt;
Below you can see a list of most important changes planned for EiffelBase2.&lt;br /&gt;
* Test extensively with AutoTest.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;PREORDER_ITERATOR&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;POSTORDER_ITERATOR&amp;lt;/e&amp;gt; to traverse binaries in pre- and postorder.&lt;br /&gt;
* Finish the implementation of the MML library.&lt;br /&gt;
* Rewrite loops using the &amp;lt;e&amp;gt;across&amp;lt;/e&amp;gt; where appropriate.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;STANDARD_INPUT&amp;lt;/e&amp;gt; streams.&lt;br /&gt;
* Add an iterator over keys for &amp;lt;e&amp;gt;TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Make the library void-safe.&lt;br /&gt;
* Implement more efficient data structures: e.g., tables with fast lookup both ways, heaps, skip lists, treaps, etc.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13803</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13803"/>
				<updated>2010-04-24T19:14:32Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Model-based contracts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2, currently under development, is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library (&amp;quot;Classic EiffelBase&amp;quot; in this document), which has for many years played a central role in Eiffel development. &lt;br /&gt;
&lt;br /&gt;
==Design goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Full contracts. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
*As in Classic EiffelBase, application of a systematic classification (a theory) of fundamental data structures.&lt;br /&gt;
&lt;br /&gt;
*Full traversal mechanisms, based on external cursors (with internal cursors also provided when useful).&lt;br /&gt;
&lt;br /&gt;
*Client-interface compatibility with corresponding classes in Classic EiffelBase, whenever it does not conflict with the preceding goals.&lt;br /&gt;
&lt;br /&gt;
==Design overview==&lt;br /&gt;
===Traversal mechanisms and classification criteria===&lt;br /&gt;
A design decision that significantly influenced the architecture of the library is using external iterators to traverse containers as apposed to internal ones available in classic EiffelBase.&lt;br /&gt;
In the design inspired by external iterators we found it natural to separate ''containers'' (with their measurements and modification means) from interfaces to access elements of containers, here called ''observers''.&lt;br /&gt;
&lt;br /&gt;
On the observer side we distinguish ''maps'' (with the defining property &amp;quot;accessing elements by unique keys&amp;quot;) and iterators (providing linear traversal). An observer can be either ''used'' by a container (as a supplier) or ''inherited'' by it. The first case produces an external access mechanism and is useful when multiple instances of an observer for the same container can exist at the same time; the second case results in an internal access mechanism and allows only one instance of an observer per container at a time. In the rest of the library maps are mostly inherited and iterators are mostly used, but this is not enforced by the design. For infinite sequences like &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; it makes sense to ''inherit'' from an iterator, because they cannot have more than one active iterator.&lt;br /&gt;
&lt;br /&gt;
On the other side, a ''container'' is a finite storage of values. Containers are deliberately confined to finite structures and understood real, physical storage. Infinite structures, instead, are usually represented as functions or mechanisms that are external to a program. Most of the time we can only access their elements (not add or remove) and for this purpose we have observers: maps and iterators (the latter in the infinite case are called ''streams'').&lt;br /&gt;
&lt;br /&gt;
Containers may be classified based on different means of modification, but previous experience shows that a complete and clean classification here is impossible (there are two many kinds of modification, basically one per &amp;quot;concrete&amp;quot; data structure). So concrete data structures mostly just inherit directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;. There is one exception: &amp;lt;e&amp;gt;SEQUENCE&amp;lt;/e&amp;gt;, which represents a sequence of values accessible by indices from a continuous interval. It serves as a common ancestor for ARRAY and LIST and factors out their common search and replacement mechanisms.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies (according to connectedness). The first one is a hierarchy of containers and maps. Note: dash-bordered ovals stand for classes that might be included in the library, but are not the first priority of the developers. All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity. &lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
The second one is a hierarchy of streams and iterators.&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
===Comparison criteria===&lt;br /&gt;
Another important design decision for a data structures library is how to represent and modify comparison criteria for container elements.&lt;br /&gt;
Adjustable comparison criterion is used is search operations and to define the uniqueness property in sets and tables (uniqueness of keys).&lt;br /&gt;
# Classic EiffelBase uses the boolean &amp;lt;e&amp;gt;object_comparison&amp;lt;/e&amp;gt; attribute in &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt; for this purpose.&lt;br /&gt;
# Gobo.structures uses another approach: storing equivalence as an object of a specific class, which can be redefined by the user to implement an arbitrary equalivalence relation.&lt;br /&gt;
# A similar approach would be to use agents to store the equalivalence relation (no need to create classes). The downside is that agents do not serialize well.&lt;br /&gt;
# Another approach is to make &amp;lt;e&amp;gt;has (x: G)&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;search (x: G)&amp;lt;/e&amp;gt; always use &amp;lt;e&amp;gt;=&amp;lt;/e&amp;gt;, but also introduce &amp;lt;e&amp;gt;exists (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;satisfy (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt;. This is more flexible (better fits cases when the predicate is not an equivalence), but duplicates the number of search features and doesn't solve the problem with sets.&lt;br /&gt;
&lt;br /&gt;
Additional question (if the comparison criterion is stored in the container) is whether it can be changed during the object lifetime. A well known practice is that in sets it is not allowed to change if the set is not empty. This gives rise to &amp;lt;e&amp;gt;changeable_comparison_criterion&amp;lt;/e&amp;gt; query in CONTAINER.&lt;br /&gt;
Note that for most set and table implementations (hashed, sorted) the comparison critearion is defined by the corresponding hash function, order, etc. and cannot be modified arbitrary even when the set or table is empty.&lt;br /&gt;
&lt;br /&gt;
The strategy chosen in EiffelBase2 is to treat differently comparison criteria on which a set or a table is based and ones just used for search. For the first the Gobo approach is taken (2 in the list above), because it is more flexible than in EiffelBase, as we can use whatever equivalence relation we want instead of just &amp;lt;e&amp;gt;is_equal&amp;lt;/e&amp;gt; (useful for library classes). Moreover, the equivalence relation is passed as an argument to the creation procedure and cannot be changed afterward. &lt;br /&gt;
&lt;br /&gt;
For search operations the approach 4 is taken, because it doesn't clutter the container state with properties that don't pertain to the container itself, but to specific search operations.&lt;br /&gt;
&lt;br /&gt;
===Indexing===&lt;br /&gt;
The current version of EiffelBase2 is using the same policy for indexing as the one used in the classic EiffelBase: indexing of lists (and iterators) always starts from 1, whereas for arrays the starting index can be set to an arbitrary value. However, during the code review in the Chair of Software Engineering (17.03.2010) is was decided that the possibility to start arrays from an arbitrary index is not crucial and is used very rarely, but complicates the API. Thus it will probably be changed in future so that indices of arrays, like those of other indexed data structures, always start at 1.&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
===Models===&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class define a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence is a model for a stack or a queue. A pair consisting of a sequence and an integer is a model for a list with an internal cursor.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
feature -- Access&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Cursor position&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of list elements&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; consisting of two components: a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
&lt;br /&gt;
===Contracts===&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of the regular features in their terms. For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. Definitions of zero-argument queries, as usual, can be moved to the class invariant. For commands we define its effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments. If a model query is not mentioned in the postcondition of a command, it is equivalent to stating that it's not modified. &lt;br /&gt;
&lt;br /&gt;
Model-based contracts approach does not constrain the way in which you write preconditions: it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space of the class.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
&lt;br /&gt;
feature -- Access&lt;br /&gt;
    item: G&lt;br /&gt;
            -- Item at current position&lt;br /&gt;
        require&lt;br /&gt;
            not_off: not off&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: Result = sequence [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Status report&lt;br /&gt;
    off: BOOLEAN&lt;br /&gt;
            -- Is cursor off all elements?&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            definition: not sequence.domain [index]&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
feature -- Element change&lt;br /&gt;
    put_right (v: G)&lt;br /&gt;
            -- Put `v' to the right of the cursor&lt;br /&gt;
        require&lt;br /&gt;
            not_after: not after&lt;br /&gt;
        deferred&lt;br /&gt;
        ensure&lt;br /&gt;
            sequence_effect: sequence |=| old (sequence.front (index).extended (v) + sequence.tail (index + 1))&lt;br /&gt;
            index_effect: index = old index&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
invariant&lt;br /&gt;
    index_in_range: 0 &amp;lt;= index and index &amp;lt;= sequence.count + 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
If a class &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; inherits from &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt; it is free to choose, whether to reuse each of &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model queries to represent its own model, as well as introduce new model queries. If &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt; does not reuse an &amp;lt;e&amp;gt;A&amp;lt;/e&amp;gt;'s model query is has to provide a ''linking invariant'': a definition of the old model query in terms of &amp;lt;e&amp;gt;B&amp;lt;/e&amp;gt;'s model. Linking invariants explain the parent's model in terms of the heir's model and thus make sure that the inherited model-based contracts make sense in the heir.&lt;br /&gt;
&lt;br /&gt;
For example, suppose that &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; inherits directly fro &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;, whose model is a bag:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: bag&lt;br /&gt;
class CONTAINER [G]&lt;br /&gt;
...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
...&lt;br /&gt;
invariant&lt;br /&gt;
    ...&lt;br /&gt;
    bag_domain_definition: bag.domain = sequence.range&lt;br /&gt;
    bag_definition: bag.domain.for all (agent (x: G): BOOLEAN&lt;br /&gt;
        do Result := bag [x] = sequence.occurrences (x) end)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here the linking invariant, provided as part of the class invariant in &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; completely defines an old model query &amp;lt;e&amp;gt;bag&amp;lt;/e&amp;gt; in terms of a new  model query &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
Development of EiffelBase has started as a project at ETH Zurich; see the [http://eiffelbase2.origo.ethz.ch/ project page]. Documentation and other material will soon be transferred to the present page.&lt;br /&gt;
&lt;br /&gt;
===ToDo list===&lt;br /&gt;
Below you can see a list of most important changes planned for EiffelBase2.&lt;br /&gt;
* Test extensively with AutoTest.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;HASH_TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;PREORDER_ITERATOR&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;POSTORDER_ITERATOR&amp;lt;/e&amp;gt; to traverse binaries in pre- and postorder.&lt;br /&gt;
* Iterator management: currently the situation when a container is modified through one iterator while it's being traversed with another is not handled anyhow.&lt;br /&gt;
* Finish the implementation of the MML library.&lt;br /&gt;
* Rewrite loops using the &amp;lt;e&amp;gt;accross&amp;lt;/e&amp;gt; where appropriate.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;STANDARD_INPUT&amp;lt;/e&amp;gt; streams.&lt;br /&gt;
* Add an iterator over keys for &amp;lt;e&amp;gt;TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Make the library void-safe.&lt;br /&gt;
* Implement more efficient data structures: e.g., tables with fast lookup both ways, heaps, skip lists, treaps, etc.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13802</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13802"/>
				<updated>2010-04-24T18:51:40Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Model-based contracts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2, currently under development, is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library (&amp;quot;Classic EiffelBase&amp;quot; in this document), which has for many years played a central role in Eiffel development. &lt;br /&gt;
&lt;br /&gt;
==Design goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Full contracts. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
*As in Classic EiffelBase, application of a systematic classification (a theory) of fundamental data structures.&lt;br /&gt;
&lt;br /&gt;
*Full traversal mechanisms, based on external cursors (with internal cursors also provided when useful).&lt;br /&gt;
&lt;br /&gt;
*Client-interface compatibility with corresponding classes in Classic EiffelBase, whenever it does not conflict with the preceding goals.&lt;br /&gt;
&lt;br /&gt;
==Design overview==&lt;br /&gt;
===Traversal mechanisms and classification criteria===&lt;br /&gt;
A design decision that significantly influenced the architecture of the library is using external iterators to traverse containers as apposed to internal ones available in classic EiffelBase.&lt;br /&gt;
In the design inspired by external iterators we found it natural to separate ''containers'' (with their measurements and modification means) from interfaces to access elements of containers, here called ''observers''.&lt;br /&gt;
&lt;br /&gt;
On the observer side we distinguish ''maps'' (with the defining property &amp;quot;accessing elements by unique keys&amp;quot;) and iterators (providing linear traversal). An observer can be either ''used'' by a container (as a supplier) or ''inherited'' by it. The first case produces an external access mechanism and is useful when multiple instances of an observer for the same container can exist at the same time; the second case results in an internal access mechanism and allows only one instance of an observer per container at a time. In the rest of the library maps are mostly inherited and iterators are mostly used, but this is not enforced by the design. For infinite sequences like &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; it makes sense to ''inherit'' from an iterator, because they cannot have more than one active iterator.&lt;br /&gt;
&lt;br /&gt;
On the other side, a ''container'' is a finite storage of values. Containers are deliberately confined to finite structures and understood real, physical storage. Infinite structures, instead, are usually represented as functions or mechanisms that are external to a program. Most of the time we can only access their elements (not add or remove) and for this purpose we have observers: maps and iterators (the latter in the infinite case are called ''streams'').&lt;br /&gt;
&lt;br /&gt;
Containers may be classified based on different means of modification, but previous experience shows that a complete and clean classification here is impossible (there are two many kinds of modification, basically one per &amp;quot;concrete&amp;quot; data structure). So concrete data structures mostly just inherit directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;. There is one exception: &amp;lt;e&amp;gt;SEQUENCE&amp;lt;/e&amp;gt;, which represents a sequence of values accessible by indices from a continuous interval. It serves as a common ancestor for ARRAY and LIST and factors out their common search and replacement mechanisms.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies (according to connectedness). The first one is a hierarchy of containers and maps. Note: dash-bordered ovals stand for classes that might be included in the library, but are not the first priority of the developers. All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity. &lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
The second one is a hierarchy of streams and iterators.&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
===Comparison criteria===&lt;br /&gt;
Another important design decision for a data structures library is how to represent and modify comparison criteria for container elements.&lt;br /&gt;
Adjustable comparison criterion is used is search operations and to define the uniqueness property in sets and tables (uniqueness of keys).&lt;br /&gt;
# Classic EiffelBase uses the boolean &amp;lt;e&amp;gt;object_comparison&amp;lt;/e&amp;gt; attribute in &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt; for this purpose.&lt;br /&gt;
# Gobo.structures uses another approach: storing equivalence as an object of a specific class, which can be redefined by the user to implement an arbitrary equalivalence relation.&lt;br /&gt;
# A similar approach would be to use agents to store the equalivalence relation (no need to create classes). The downside is that agents do not serialize well.&lt;br /&gt;
# Another approach is to make &amp;lt;e&amp;gt;has (x: G)&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;search (x: G)&amp;lt;/e&amp;gt; always use &amp;lt;e&amp;gt;=&amp;lt;/e&amp;gt;, but also introduce &amp;lt;e&amp;gt;exists (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;satisfy (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt;. This is more flexible (better fits cases when the predicate is not an equivalence), but duplicates the number of search features and doesn't solve the problem with sets.&lt;br /&gt;
&lt;br /&gt;
Additional question (if the comparison criterion is stored in the container) is whether it can be changed during the object lifetime. A well known practice is that in sets it is not allowed to change if the set is not empty. This gives rise to &amp;lt;e&amp;gt;changeable_comparison_criterion&amp;lt;/e&amp;gt; query in CONTAINER.&lt;br /&gt;
Note that for most set and table implementations (hashed, sorted) the comparison critearion is defined by the corresponding hash function, order, etc. and cannot be modified arbitrary even when the set or table is empty.&lt;br /&gt;
&lt;br /&gt;
The strategy chosen in EiffelBase2 is to treat differently comparison criteria on which a set or a table is based and ones just used for search. For the first the Gobo approach is taken (2 in the list above), because it is more flexible than in EiffelBase, as we can use whatever equivalence relation we want instead of just &amp;lt;e&amp;gt;is_equal&amp;lt;/e&amp;gt; (useful for library classes). Moreover, the equivalence relation is passed as an argument to the creation procedure and cannot be changed afterward. &lt;br /&gt;
&lt;br /&gt;
For search operations the approach 4 is taken, because it doesn't clutter the container state with properties that don't pertain to the container itself, but to specific search operations.&lt;br /&gt;
&lt;br /&gt;
===Indexing===&lt;br /&gt;
The current version of EiffelBase2 is using the same policy for indexing as the one used in the classic EiffelBase: indexing of lists (and iterators) always starts from 1, whereas for arrays the starting index can be set to an arbitrary value. However, during the code review in the Chair of Software Engineering (17.03.2010) is was decided that the possibility to start arrays from an arbitrary index is not crucial and is used very rarely, but complicates the API. Thus it will probably be changed in future so that indices of arrays, like those of other indexed data structures, always start at 1.&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class define a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence is a model for a stack or a queue. A pair consisting of a sequence and an integer is a model for a list with an internal cursor.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
feature -- Access&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
            -- Cursor position&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
            -- Sequence of list elements&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; consisting of two components: a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
&lt;br /&gt;
The purpose of introducing model queries is to define the postconditions of the regular features in their terms. For queries we define their result (or the model of the result, in case the query returns a fresh object) as a function of the model of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and (the models of) the arguments. For commands we define its effects on the model queries of &amp;lt;e&amp;gt;Current&amp;lt;/e&amp;gt; and the arguments. If a model query is not mentioned in the postcondition of a command, it is equivalent to stating that it's not modified. &lt;br /&gt;
&lt;br /&gt;
Model-based contracts approach does not constrain the way in which you write preconditions: it is not necessary to express them through model queries if they can be conveniently expressed otherwise.&lt;br /&gt;
&lt;br /&gt;
Class invariants in model-based contracts approach constrain the values of model queries to make them reflect precisely the abstract state space.&lt;br /&gt;
&lt;br /&gt;
Let us add a couple of features and model-based contracts into the class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; shown above:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
off: BOOLEAN&lt;br /&gt;
        -- Is cursor off all elements?&lt;br /&gt;
    deferred&lt;br /&gt;
    ensure&lt;br /&gt;
        definition: not sequence.domain [index]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
item: G&lt;br /&gt;
        -- Item at current position&lt;br /&gt;
    require&lt;br /&gt;
        not_off: not off&lt;br /&gt;
    deferred&lt;br /&gt;
    ensure&lt;br /&gt;
        definition: Result = sequence [index]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
put_right (v: G)&lt;br /&gt;
        -- Put `v' to the right of the cursor&lt;br /&gt;
    require&lt;br /&gt;
        not_after: not after&lt;br /&gt;
    deferred&lt;br /&gt;
    ensure&lt;br /&gt;
        sequence_effect: sequence |=| old (sequence.front (index).extended (v) + sequence.tail (index + 1))&lt;br /&gt;
        index_effect: index = old index&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
Development of EiffelBase has started as a project at ETH Zurich; see the [http://eiffelbase2.origo.ethz.ch/ project page]. Documentation and other material will soon be transferred to the present page.&lt;br /&gt;
&lt;br /&gt;
===ToDo list===&lt;br /&gt;
Below you can see a list of most important changes planned for EiffelBase2.&lt;br /&gt;
* Test extensively with AutoTest.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;HASH_TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;PREORDER_ITERATOR&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;POSTORDER_ITERATOR&amp;lt;/e&amp;gt; to traverse binaries in pre- and postorder.&lt;br /&gt;
* Iterator management: currently the situation when a container is modified through one iterator while it's being traversed with another is not handled anyhow.&lt;br /&gt;
* Finish the implementation of the MML library.&lt;br /&gt;
* Rewrite loops using the &amp;lt;e&amp;gt;accross&amp;lt;/e&amp;gt; where appropriate.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;STANDARD_INPUT&amp;lt;/e&amp;gt; streams.&lt;br /&gt;
* Add an iterator over keys for &amp;lt;e&amp;gt;TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Make the library void-safe.&lt;br /&gt;
* Implement more efficient data structures: e.g., tables with fast lookup both ways, heaps, skip lists, treaps, etc.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13801</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13801"/>
				<updated>2010-04-24T18:29:16Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2, currently under development, is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library (&amp;quot;Classic EiffelBase&amp;quot; in this document), which has for many years played a central role in Eiffel development. &lt;br /&gt;
&lt;br /&gt;
==Design goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Full contracts. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
*As in Classic EiffelBase, application of a systematic classification (a theory) of fundamental data structures.&lt;br /&gt;
&lt;br /&gt;
*Full traversal mechanisms, based on external cursors (with internal cursors also provided when useful).&lt;br /&gt;
&lt;br /&gt;
*Client-interface compatibility with corresponding classes in Classic EiffelBase, whenever it does not conflict with the preceding goals.&lt;br /&gt;
&lt;br /&gt;
==Design overview==&lt;br /&gt;
===Traversal mechanisms and classification criteria===&lt;br /&gt;
A design decision that significantly influenced the architecture of the library is using external iterators to traverse containers as apposed to internal ones available in classic EiffelBase.&lt;br /&gt;
In the design inspired by external iterators we found it natural to separate ''containers'' (with their measurements and modification means) from interfaces to access elements of containers, here called ''observers''.&lt;br /&gt;
&lt;br /&gt;
On the observer side we distinguish ''maps'' (with the defining property &amp;quot;accessing elements by unique keys&amp;quot;) and iterators (providing linear traversal). An observer can be either ''used'' by a container (as a supplier) or ''inherited'' by it. The first case produces an external access mechanism and is useful when multiple instances of an observer for the same container can exist at the same time; the second case results in an internal access mechanism and allows only one instance of an observer per container at a time. In the rest of the library maps are mostly inherited and iterators are mostly used, but this is not enforced by the design. For infinite sequences like &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; it makes sense to ''inherit'' from an iterator, because they cannot have more than one active iterator.&lt;br /&gt;
&lt;br /&gt;
On the other side, a ''container'' is a finite storage of values. Containers are deliberately confined to finite structures and understood real, physical storage. Infinite structures, instead, are usually represented as functions or mechanisms that are external to a program. Most of the time we can only access their elements (not add or remove) and for this purpose we have observers: maps and iterators (the latter in the infinite case are called ''streams'').&lt;br /&gt;
&lt;br /&gt;
Containers may be classified based on different means of modification, but previous experience shows that a complete and clean classification here is impossible (there are two many kinds of modification, basically one per &amp;quot;concrete&amp;quot; data structure). So concrete data structures mostly just inherit directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;. There is one exception: &amp;lt;e&amp;gt;SEQUENCE&amp;lt;/e&amp;gt;, which represents a sequence of values accessible by indices from a continuous interval. It serves as a common ancestor for ARRAY and LIST and factors out their common search and replacement mechanisms.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies (according to connectedness). The first one is a hierarchy of containers and maps. Note: dash-bordered ovals stand for classes that might be included in the library, but are not the first priority of the developers. All EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the current document for brevity. &lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
The second one is a hierarchy of streams and iterators.&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
===Comparison criteria===&lt;br /&gt;
Another important design decision for a data structures library is how to represent and modify comparison criteria for container elements.&lt;br /&gt;
Adjustable comparison criterion is used is search operations and to define the uniqueness property in sets and tables (uniqueness of keys).&lt;br /&gt;
# Classic EiffelBase uses the boolean &amp;lt;e&amp;gt;object_comparison&amp;lt;/e&amp;gt; attribute in &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt; for this purpose.&lt;br /&gt;
# Gobo.structures uses another approach: storing equivalence as an object of a specific class, which can be redefined by the user to implement an arbitrary equalivalence relation.&lt;br /&gt;
# A similar approach would be to use agents to store the equalivalence relation (no need to create classes). The downside is that agents do not serialize well.&lt;br /&gt;
# Another approach is to make &amp;lt;e&amp;gt;has (x: G)&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;search (x: G)&amp;lt;/e&amp;gt; always use &amp;lt;e&amp;gt;=&amp;lt;/e&amp;gt;, but also introduce &amp;lt;e&amp;gt;exists (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;satisfy (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt;. This is more flexible (better fits cases when the predicate is not an equivalence), but duplicates the number of search features and doesn't solve the problem with sets.&lt;br /&gt;
&lt;br /&gt;
Additional question (if the comparison criterion is stored in the container) is whether it can be changed during the object lifetime. A well known practice is that in sets it is not allowed to change if the set is not empty. This gives rise to &amp;lt;e&amp;gt;changeable_comparison_criterion&amp;lt;/e&amp;gt; query in CONTAINER.&lt;br /&gt;
Note that for most set and table implementations (hashed, sorted) the comparison critearion is defined by the corresponding hash function, order, etc. and cannot be modified arbitrary even when the set or table is empty.&lt;br /&gt;
&lt;br /&gt;
The strategy chosen in EiffelBase2 is to treat differently comparison criteria on which a set or a table is based and ones just used for search. For the first the Gobo approach is taken (2 in the list above), because it is more flexible than in EiffelBase, as we can use whatever equivalence relation we want instead of just &amp;lt;e&amp;gt;is_equal&amp;lt;/e&amp;gt; (useful for library classes). Moreover, the equivalence relation is passed as an argument to the creation procedure and cannot be changed afterward. &lt;br /&gt;
&lt;br /&gt;
For search operations the approach 4 is taken, because it doesn't clutter the container state with properties that don't pertain to the container itself, but to specific search operations.&lt;br /&gt;
&lt;br /&gt;
===Indexing===&lt;br /&gt;
The current version of EiffelBase2 is using the same policy for indexing as the one used in the classic EiffelBase: indexing of lists (and iterators) always starts from 1, whereas for arrays the starting index can be set to an arbitrary value. However, during the code review in the Chair of Software Engineering (17.03.2010) is was decided that the possibility to start arrays from an arbitrary index is not crucial and is used very rarely, but complicates the API. Thus it will probably be changed in future so that indices of arrays, like those of other indexed data structures, always start at 1.&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class define a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence is a model for a stack or a queue. A pair consisting of a sequence and an integer is a model for a list with an internal cursor.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
feature -- Access&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; consisting of two components: a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
Development of EiffelBase has started as a project at ETH Zurich; see the [http://eiffelbase2.origo.ethz.ch/ project page]. Documentation and other material will soon be transferred to the present page.&lt;br /&gt;
&lt;br /&gt;
===ToDo list===&lt;br /&gt;
Below you can see a list of most important changes planned for EiffelBase2.&lt;br /&gt;
* Test extensively with AutoTest.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;HASH_TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;PREORDER_ITERATOR&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;POSTORDER_ITERATOR&amp;lt;/e&amp;gt; to traverse binaries in pre- and postorder.&lt;br /&gt;
* Iterator management: currently the situation when a container is modified through one iterator while it's being traversed with another is not handled anyhow.&lt;br /&gt;
* Finish the implementation of the MML library.&lt;br /&gt;
* Rewrite loops using the &amp;lt;e&amp;gt;accross&amp;lt;/e&amp;gt; where appropriate.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;STANDARD_INPUT&amp;lt;/e&amp;gt; streams.&lt;br /&gt;
* Add an iterator over keys for &amp;lt;e&amp;gt;TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Make the library void-safe.&lt;br /&gt;
* Implement more efficient data structures: e.g., tables with fast lookup both ways, heaps, skip lists, treaps, etc.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13800</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13800"/>
				<updated>2010-04-24T18:26:22Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2, currently under development, is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library (&amp;quot;Classic EiffelBase&amp;quot; in this document), which has for many years played a central role in Eiffel development. &lt;br /&gt;
&lt;br /&gt;
==Design goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Full contracts. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
*As in Classic EiffelBase, application of a systematic classification (a theory) of fundamental data structures.&lt;br /&gt;
&lt;br /&gt;
*Full traversal mechanisms, based on external cursors (with internal cursors also provided when useful).&lt;br /&gt;
&lt;br /&gt;
*Client-interface compatibility with corresponding classes in Classic EiffelBase, whenever it does not conflict with the preceding goals.&lt;br /&gt;
&lt;br /&gt;
==Design overview==&lt;br /&gt;
===Traversal mechanisms and classification criteria===&lt;br /&gt;
A design decision that significantly influenced the architecture of the library is using external iterators to traverse containers as apposed to internal ones available in classic EiffelBase.&lt;br /&gt;
In the design inspired by external iterators we found it natural to separate ''containers'' (with their measurements and modification means) from interfaces to access elements of containers, here called ''observers''.&lt;br /&gt;
&lt;br /&gt;
On the observer side we distinguish ''maps'' (with the defining property &amp;quot;accessing elements by unique keys&amp;quot;) and iterators (providing linear traversal). An observer can be either ''used'' by a container (as a supplier) or ''inherited'' by it. The first case produces an external access mechanism and is useful when multiple instances of an observer for the same container can exist at the same time; the second case results in an internal access mechanism and allows only one instance of an observer per container at a time. In the rest of the library maps are mostly inherited and iterators are mostly used, but this is not enforced by the design. For infinite sequences like &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; it makes sense to ''inherit'' from an iterator, because they cannot have more than one active iterator.&lt;br /&gt;
&lt;br /&gt;
On the other side, a ''container'' is a finite storage of values. Containers are deliberately confined to finite structures and understood real, physical storage. Infinite structures, instead, are usually represented as functions or mechanisms that are external to a program. Most of the time we can only access their elements (not add or remove) and for this purpose we have observers: maps and iterators (the latter in the infinite case are called ''streams'').&lt;br /&gt;
&lt;br /&gt;
Containers may be classified based on different means of modification, but previous experience shows that a complete and clean classification here is impossible (there are two many kinds of modification, basically one per &amp;quot;concrete&amp;quot; data structure). So concrete data structures mostly just inherit directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;&amp;lt;ref&amp;gt;EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the document.&amp;lt;/ref&amp;gt;. There is one exception: &amp;lt;e&amp;gt;SEQUENCE&amp;lt;/e&amp;gt;, which represents a sequence of values accessible by indices from a continuous interval. It serves as a common ancestor for ARRAY and LIST and factors out their common search and replacement mechanisms.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies (according to connectedness). The first one is a hierarchy of containers and maps. Note: dash-bordered ovals stand for classes that might be included in the library, but are not the first priority of the developers.  &lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
The second one is a hierarchy of streams and iterators.&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
===Comparison criteria===&lt;br /&gt;
Another important design decision for a data structures library is how to represent and modify comparison criteria for container elements.&lt;br /&gt;
Adjustable comparison criterion is used is search operations and to define the uniqueness property in sets and tables (uniqueness of keys).&lt;br /&gt;
# Classic EiffelBase uses the boolean &amp;lt;e&amp;gt;object_comparison&amp;lt;/e&amp;gt; attribute in &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt; for this purpose.&lt;br /&gt;
# Gobo.structures uses another approach: storing equivalence as an object of a specific class, which can be redefined by the user to implement an arbitrary equalivalence relation.&lt;br /&gt;
# A similar approach would be to use agents to store the equalivalence relation (no need to create classes). The downside is that agents do not serialize well.&lt;br /&gt;
# Another approach is to make &amp;lt;e&amp;gt;has (x: G)&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;search (x: G)&amp;lt;/e&amp;gt; always use &amp;lt;e&amp;gt;=&amp;lt;/e&amp;gt;, but also introduce &amp;lt;e&amp;gt;exists (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;satisfy (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt;. This is more flexible (better fits cases when the predicate is not an equivalence), but duplicates the number of search features and doesn't solve the problem with sets.&lt;br /&gt;
&lt;br /&gt;
Additional question (if the comparison criterion is stored in the container) is whether it can be changed during the object lifetime. A well known practice is that in sets it is not allowed to change if the set is not empty. This gives rise to &amp;lt;e&amp;gt;changeable_comparison_criterion&amp;lt;/e&amp;gt; query in CONTAINER.&lt;br /&gt;
Note that for most set and table implementations (hashed, sorted) the comparison critearion is defined by the corresponding hash function, order, etc. and cannot be modified arbitrary even when the set or table is empty.&lt;br /&gt;
&lt;br /&gt;
The strategy chosen in EiffelBase2 is to treat differently comparison criteria on which a set or a table is based and ones just used for search. For the first the Gobo approach is taken (2 in the list above), because it is more flexible than in EiffelBase, as we can use whatever equivalence relation we want instead of just &amp;lt;e&amp;gt;is_equal&amp;lt;/e&amp;gt; (useful for library classes). Moreover, the equivalence relation is passed as an argument to the creation procedure and cannot be changed afterward. &lt;br /&gt;
&lt;br /&gt;
For search operations the approach 4 is taken, because it doesn't clutter the container state with properties that don't pertain to the container itself, but to specific search operations.&lt;br /&gt;
&lt;br /&gt;
===Indexing===&lt;br /&gt;
The current version of EiffelBase2 is using the same policy for indexing as the one used in the classic EiffelBase: indexing of lists (and iterators) always starts from 1, whereas for arrays the starting index can be set to an arbitrary value. However, during the code review in the Chair of Software Engineering (17.03.2010) is was decided that the possibility to start arrays from an arbitrary index is not crucial and is used very rarely, but complicates the API. Thus it will probably be changed in future so that indices of arrays, like those of other indexed data structures, always start at 1.&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class define a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence is a model for a stack or a queue. A pair consisting of a sequence and an integer is a model for a list with an internal cursor.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
feature -- Access&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; consisting of two components: a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
Development of EiffelBase has started as a project at ETH Zurich; see the [http://eiffelbase2.origo.ethz.ch/ project page]. Documentation and other material will soon be transferred to the present page.&lt;br /&gt;
&lt;br /&gt;
===ToDo list===&lt;br /&gt;
Below you can see a list of most important changes planned for EiffelBase2.&lt;br /&gt;
* Test extensively with AutoTest.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;HASH_TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;PREORDER_ITERATOR&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;POSTORDER_ITERATOR&amp;lt;/e&amp;gt; to traverse binaries in pre- and postorder.&lt;br /&gt;
* Iterator management: currently the situation when a container is modified through one iterator while it's being traversed with another is not handled anyhow.&lt;br /&gt;
* Finish the implementation of the MML library.&lt;br /&gt;
* Rewrite loops using the &amp;lt;e&amp;gt;accross&amp;lt;/e&amp;gt; where appropriate.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;STANDARD_INPUT&amp;lt;/e&amp;gt; streams.&lt;br /&gt;
* Add an iterator over keys for &amp;lt;e&amp;gt;TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Make the library void-safe.&lt;br /&gt;
* Implement more efficient data structures: e.g., tables with fast lookup both ways, heaps, skip lists, treaps, etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13799</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13799"/>
				<updated>2010-04-24T18:25:53Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Traversal mechanisms and classification criteria */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2, currently under development, is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library (&amp;quot;Classic EiffelBase&amp;quot; in this document), which has for many years played a central role in Eiffel development. &lt;br /&gt;
&lt;br /&gt;
==Design goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Full contracts. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
*As in Classic EiffelBase, application of a systematic classification (a theory) of fundamental data structures.&lt;br /&gt;
&lt;br /&gt;
*Full traversal mechanisms, based on external cursors (with internal cursors also provided when useful).&lt;br /&gt;
&lt;br /&gt;
*Client-interface compatibility with corresponding classes in Classic EiffelBase, whenever it does not conflict with the preceding goals.&lt;br /&gt;
&lt;br /&gt;
==Design overview==&lt;br /&gt;
===Traversal mechanisms and classification criteria===&lt;br /&gt;
A design decision that significantly influenced the architecture of the library is using external iterators to traverse containers as apposed to internal ones available in classic EiffelBase.&lt;br /&gt;
In the design inspired by external iterators we found it natural to separate ''containers'' (with their measurements and modification means) from interfaces to access elements of containers, here called ''observers''.&lt;br /&gt;
&lt;br /&gt;
On the observer side we distinguish ''maps'' (with the defining property &amp;quot;accessing elements by unique keys&amp;quot;) and iterators (providing linear traversal). An observer can be either ''used'' by a container (as a supplier) or ''inherited'' by it. The first case produces an external access mechanism and is useful when multiple instances of an observer for the same container can exist at the same time; the second case results in an internal access mechanism and allows only one instance of an observer per container at a time. In the rest of the library maps are mostly inherited and iterators are mostly used, but this is not enforced by the design. For infinite sequences like &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; it makes sense to ''inherit'' from an iterator, because they cannot have more than one active iterator.&lt;br /&gt;
&lt;br /&gt;
On the other side, a ''container'' is a finite storage of values. Containers are deliberately confined to finite structures and understood real, physical storage. Infinite structures, instead, are usually represented as functions or mechanisms that are external to a program. Most of the time we can only access their elements (not add or remove) and for this purpose we have observers: maps and iterators (the latter in the infinite case are called ''streams'').&lt;br /&gt;
&lt;br /&gt;
Containers may be classified based on different means of modification, but previous experience shows that a complete and clean classification here is impossible (there are two many kinds of modification, basically one per &amp;quot;concrete&amp;quot; data structure). So concrete data structures mostly just inherit directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;&amp;lt;ref&amp;gt;EiffelBase2 class names start with &amp;lt;e&amp;gt;V_&amp;lt;/e&amp;gt; (for ''Verified''), but the prefix is omitted in the document.&amp;lt;/ref&amp;gt;. There is one exception: &amp;lt;e&amp;gt;SEQUENCE&amp;lt;/e&amp;gt;, which represents a sequence of values accessible by indices from a continuous interval. It serves as a common ancestor for ARRAY and LIST and factors out their common search and replacement mechanisms.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies (according to connectedness). The first one is a hierarchy of containers and maps. Note: dash-bordered ovals stand for classes that might be included in the library, but are not the first priority of the developers.  &lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
The second one is a hierarchy of streams and iterators.&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
===Comparison criteria===&lt;br /&gt;
Another important design decision for a data structures library is how to represent and modify comparison criteria for container elements.&lt;br /&gt;
Adjustable comparison criterion is used is search operations and to define the uniqueness property in sets and tables (uniqueness of keys).&lt;br /&gt;
# Classic EiffelBase uses the boolean &amp;lt;e&amp;gt;object_comparison&amp;lt;/e&amp;gt; attribute in &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt; for this purpose.&lt;br /&gt;
# Gobo.structures uses another approach: storing equivalence as an object of a specific class, which can be redefined by the user to implement an arbitrary equalivalence relation.&lt;br /&gt;
# A similar approach would be to use agents to store the equalivalence relation (no need to create classes). The downside is that agents do not serialize well.&lt;br /&gt;
# Another approach is to make &amp;lt;e&amp;gt;has (x: G)&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;search (x: G)&amp;lt;/e&amp;gt; always use &amp;lt;e&amp;gt;=&amp;lt;/e&amp;gt;, but also introduce &amp;lt;e&amp;gt;exists (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;satisfy (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt;. This is more flexible (better fits cases when the predicate is not an equivalence), but duplicates the number of search features and doesn't solve the problem with sets.&lt;br /&gt;
&lt;br /&gt;
Additional question (if the comparison criterion is stored in the container) is whether it can be changed during the object lifetime. A well known practice is that in sets it is not allowed to change if the set is not empty. This gives rise to &amp;lt;e&amp;gt;changeable_comparison_criterion&amp;lt;/e&amp;gt; query in CONTAINER.&lt;br /&gt;
Note that for most set and table implementations (hashed, sorted) the comparison critearion is defined by the corresponding hash function, order, etc. and cannot be modified arbitrary even when the set or table is empty.&lt;br /&gt;
&lt;br /&gt;
The strategy chosen in EiffelBase2 is to treat differently comparison criteria on which a set or a table is based and ones just used for search. For the first the Gobo approach is taken (2 in the list above), because it is more flexible than in EiffelBase, as we can use whatever equivalence relation we want instead of just &amp;lt;e&amp;gt;is_equal&amp;lt;/e&amp;gt; (useful for library classes). Moreover, the equivalence relation is passed as an argument to the creation procedure and cannot be changed afterward. &lt;br /&gt;
&lt;br /&gt;
For search operations the approach 4 is taken, because it doesn't clutter the container state with properties that don't pertain to the container itself, but to specific search operations.&lt;br /&gt;
&lt;br /&gt;
===Indexing===&lt;br /&gt;
The current version of EiffelBase2 is using the same policy for indexing as the one used in the classic EiffelBase: indexing of lists (and iterators) always starts from 1, whereas for arrays the starting index can be set to an arbitrary value. However, during the code review in the Chair of Software Engineering (17.03.2010) is was decided that the possibility to start arrays from an arbitrary index is not crucial and is used very rarely, but complicates the API. Thus it will probably be changed in future so that indices of arrays, like those of other indexed data structures, always start at 1.&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class define a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence is a model for a stack or a queue. A pair consisting of a sequence and an integer is a model for a list with an internal cursor.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
feature -- Access&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; consisting of two components: a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
Development of EiffelBase has started as a project at ETH Zurich; see the [http://eiffelbase2.origo.ethz.ch/ project page]. Documentation and other material will soon be transferred to the present page.&lt;br /&gt;
&lt;br /&gt;
===ToDo list===&lt;br /&gt;
Below you can see a list of most important changes planned for EiffelBase2.&lt;br /&gt;
* Test extensively with AutoTest.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;HASH_TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;PREORDER_ITERATOR&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;POSTORDER_ITERATOR&amp;lt;/e&amp;gt; to traverse binaries in pre- and postorder.&lt;br /&gt;
* Iterator management: currently the situation when a container is modified through one iterator while it's being traversed with another is not handled anyhow.&lt;br /&gt;
* Finish the implementation of the MML library.&lt;br /&gt;
* Rewrite loops using the &amp;lt;e&amp;gt;accross&amp;lt;/e&amp;gt; where appropriate.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;STANDARD_INPUT&amp;lt;/e&amp;gt; streams.&lt;br /&gt;
* Add an iterator over keys for &amp;lt;e&amp;gt;TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Make the library void-safe.&lt;br /&gt;
* Implement more efficient data structures: e.g., tables with fast lookup both ways, heaps, skip lists, treaps, etc.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13798</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13798"/>
				<updated>2010-04-24T18:18:54Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Model-based contracts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2, currently under development, is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library (&amp;quot;Classic EiffelBase&amp;quot; in this document), which has for many years played a central role in Eiffel development. &lt;br /&gt;
&lt;br /&gt;
==Design goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Full contracts. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
*As in Classic EiffelBase, application of a systematic classification (a theory) of fundamental data structures.&lt;br /&gt;
&lt;br /&gt;
*Full traversal mechanisms, based on external cursors (with internal cursors also provided when useful).&lt;br /&gt;
&lt;br /&gt;
*Client-interface compatibility with corresponding classes in Classic EiffelBase, whenever it does not conflict with the preceding goals.&lt;br /&gt;
&lt;br /&gt;
==Design overview==&lt;br /&gt;
===Traversal mechanisms and classification criteria===&lt;br /&gt;
A design decision that significantly influenced the architecture of the library is using external iterators to traverse containers as apposed to internal ones available in classic EiffelBase.&lt;br /&gt;
In the design inspired by external iterators we found it natural to separate ''containers'' (with their measurements and modification means) from interfaces to access elements of containers, here called ''observers''.&lt;br /&gt;
&lt;br /&gt;
On the observer side we distinguish ''maps'' (with the defining property &amp;quot;accessing elements by unique keys&amp;quot;) and iterators (providing linear traversal). An observer can be either ''used'' by a container (as a supplier) or ''inherited'' by it. The first case produces an external access mechanism and is useful when multiple instances of an observer for the same container can exist at the same time; the second case results in an internal access mechanism and allows only one instance of an observer per container at a time. In the rest of the library maps are mostly inherited and iterators are mostly used, but this is not enforced by the design. For infinite sequences like &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; it makes sense to ''inherit'' from an iterator, because they cannot have more than one active iterator.&lt;br /&gt;
&lt;br /&gt;
On the other side, a ''container'' is a finite storage of values. Containers are deliberately confined to finite structures and understood real, physical storage. Infinite structures, instead, are usually represented as functions or mechanisms that are external to a program. Most of the time we can only access their elements (not add or remove) and for this purpose we have observers: maps and iterators (the latter in the infinite case are called ''streams'').&lt;br /&gt;
&lt;br /&gt;
Containers may be classified based on different means of modification, but previous experience shows that a complete and clean classification here is impossible (there are two many kinds of modification, basically one per &amp;quot;concrete&amp;quot; data structure). So concrete data structures mostly just inherit directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;. There is one exception: &amp;lt;e&amp;gt;SEQUENCE&amp;lt;/e&amp;gt;, which represents a sequence of values accessible by indices from a continuous interval. It serves as a common ancestor for ARRAY and LIST and factors out their common search and replacement mechanisms.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies (according to connectedness). The first one is a hierarchy of containers and maps. Note: dash-bordered ovals stand for classes that might be included in the library, but are not the first priority of the developers.  &lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
The second one is a hierarchy of streams and iterators.&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
===Comparison criteria===&lt;br /&gt;
Another important design decision for a data structures library is how to represent and modify comparison criteria for container elements.&lt;br /&gt;
Adjustable comparison criterion is used is search operations and to define the uniqueness property in sets and tables (uniqueness of keys).&lt;br /&gt;
# Classic EiffelBase uses the boolean &amp;lt;e&amp;gt;object_comparison&amp;lt;/e&amp;gt; attribute in &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt; for this purpose.&lt;br /&gt;
# Gobo.structures uses another approach: storing equivalence as an object of a specific class, which can be redefined by the user to implement an arbitrary equalivalence relation.&lt;br /&gt;
# A similar approach would be to use agents to store the equalivalence relation (no need to create classes). The downside is that agents do not serialize well.&lt;br /&gt;
# Another approach is to make &amp;lt;e&amp;gt;has (x: G)&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;search (x: G)&amp;lt;/e&amp;gt; always use &amp;lt;e&amp;gt;=&amp;lt;/e&amp;gt;, but also introduce &amp;lt;e&amp;gt;exists (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;satisfy (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt;. This is more flexible (better fits cases when the predicate is not an equivalence), but duplicates the number of search features and doesn't solve the problem with sets.&lt;br /&gt;
&lt;br /&gt;
Additional question (if the comparison criterion is stored in the container) is whether it can be changed during the object lifetime. A well known practice is that in sets it is not allowed to change if the set is not empty. This gives rise to &amp;lt;e&amp;gt;changeable_comparison_criterion&amp;lt;/e&amp;gt; query in CONTAINER.&lt;br /&gt;
Note that for most set and table implementations (hashed, sorted) the comparison critearion is defined by the corresponding hash function, order, etc. and cannot be modified arbitrary even when the set or table is empty.&lt;br /&gt;
&lt;br /&gt;
The strategy chosen in EiffelBase2 is to treat differently comparison criteria on which a set or a table is based and ones just used for search. For the first the Gobo approach is taken (2 in the list above), because it is more flexible than in EiffelBase, as we can use whatever equivalence relation we want instead of just &amp;lt;e&amp;gt;is_equal&amp;lt;/e&amp;gt; (useful for library classes). Moreover, the equivalence relation is passed as an argument to the creation procedure and cannot be changed afterward. &lt;br /&gt;
&lt;br /&gt;
For search operations the approach 4 is taken, because it doesn't clutter the container state with properties that don't pertain to the container itself, but to specific search operations.&lt;br /&gt;
&lt;br /&gt;
===Indexing===&lt;br /&gt;
The current version of EiffelBase2 is using the same policy for indexing as the one used in the classic EiffelBase: indexing of lists (and iterators) always starts from 1, whereas for arrays the starting index can be set to an arbitrary value. However, during the code review in the Chair of Software Engineering (17.03.2010) is was decided that the possibility to start arrays from an arbitrary index is not crucial and is used very rarely, but complicates the API. Thus it will probably be changed in future so that indices of arrays, like those of other indexed data structures, always start at 1.&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class define a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The Mathematical Model Library (MML), which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;e&amp;gt;BOOLEAN&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;INTEGER&amp;lt;/e&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
For example, a mathematical sequence is a model for a stack or a queue. A pair consisting of a sequence and an integer is a model for a list with an internal cursor.&lt;br /&gt;
&lt;br /&gt;
The value of each component of the model is defined by a ''model query''. You define the model of the class in the source code by listing its model queries under the tag &amp;lt;e&amp;gt;model&amp;lt;/e&amp;gt; in the class's &amp;lt;e&amp;gt;note&amp;lt;/e&amp;gt; clause. For example:&lt;br /&gt;
&amp;lt;e&amp;gt;&lt;br /&gt;
note&lt;br /&gt;
    model: sequence, index&lt;br /&gt;
class LIST [G]&lt;br /&gt;
feature -- Access&lt;br /&gt;
    index: INTEGER&lt;br /&gt;
        deferred&lt;br /&gt;
        end&lt;br /&gt;
...&lt;br /&gt;
feature -- Specification&lt;br /&gt;
    sequence: MML_SEQUENCE [G]&lt;br /&gt;
        note&lt;br /&gt;
            status: specification&lt;br /&gt;
        ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/e&amp;gt;&lt;br /&gt;
Here we declared the model of class &amp;lt;e&amp;gt;LIST&amp;lt;/e&amp;gt; consisting of two components: a mathematical sequence of type &amp;lt;e&amp;gt;MML_SEQUENCE&amp;lt;/e&amp;gt; and an integer index. As you can see, model queries are not necessarily introduced specifically for specification purposes (as is the case with &amp;lt;e&amp;gt;sequence&amp;lt;/e&amp;gt;); regular queries meant to be called from the code can be also reused as model queries (as &amp;lt;e&amp;gt;index&amp;lt;/e&amp;gt; in this example). We attach a &amp;lt;e&amp;gt;status: specification&amp;lt;/e&amp;gt; note to a query to indicate that its primary purpose is specification.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
Development of EiffelBase has started as a project at ETH Zurich; see the [http://eiffelbase2.origo.ethz.ch/ project page]. Documentation and other material will soon be transferred to the present page.&lt;br /&gt;
&lt;br /&gt;
===ToDo list===&lt;br /&gt;
Below you can see a list of most important changes planned for EiffelBase2.&lt;br /&gt;
* Test extensively with AutoTest.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;HASH_TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;PREORDER_ITERATOR&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;POSTORDER_ITERATOR&amp;lt;/e&amp;gt; to traverse binaries in pre- and postorder.&lt;br /&gt;
* Iterator management: currently the situation when a container is modified through one iterator while it's being traversed with another is not handled anyhow.&lt;br /&gt;
* Finish the implementation of the MML library.&lt;br /&gt;
* Rewrite loops using the &amp;lt;e&amp;gt;accross&amp;lt;/e&amp;gt; where appropriate.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;STANDARD_INPUT&amp;lt;/e&amp;gt; streams.&lt;br /&gt;
* Add an iterator over keys for &amp;lt;e&amp;gt;TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Make the library void-safe.&lt;br /&gt;
* Implement more efficient data structures: e.g., tables with fast lookup both ways, heaps, skip lists, treaps, etc.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13797</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13797"/>
				<updated>2010-04-24T17:58:38Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Model-based contracts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2, currently under development, is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library (&amp;quot;Classic EiffelBase&amp;quot; in this document), which has for many years played a central role in Eiffel development. &lt;br /&gt;
&lt;br /&gt;
==Design goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Full contracts. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
*As in Classic EiffelBase, application of a systematic classification (a theory) of fundamental data structures.&lt;br /&gt;
&lt;br /&gt;
*Full traversal mechanisms, based on external cursors (with internal cursors also provided when useful).&lt;br /&gt;
&lt;br /&gt;
*Client-interface compatibility with corresponding classes in Classic EiffelBase, whenever it does not conflict with the preceding goals.&lt;br /&gt;
&lt;br /&gt;
==Design overview==&lt;br /&gt;
===Traversal mechanisms and classification criteria===&lt;br /&gt;
A design decision that significantly influenced the architecture of the library is using external iterators to traverse containers as apposed to internal ones available in classic EiffelBase.&lt;br /&gt;
In the design inspired by external iterators we found it natural to separate ''containers'' (with their measurements and modification means) from interfaces to access elements of containers, here called ''observers''.&lt;br /&gt;
&lt;br /&gt;
On the observer side we distinguish ''maps'' (with the defining property &amp;quot;accessing elements by unique keys&amp;quot;) and iterators (providing linear traversal). An observer can be either ''used'' by a container (as a supplier) or ''inherited'' by it. The first case produces an external access mechanism and is useful when multiple instances of an observer for the same container can exist at the same time; the second case results in an internal access mechanism and allows only one instance of an observer per container at a time. In the rest of the library maps are mostly inherited and iterators are mostly used, but this is not enforced by the design. For infinite sequences like &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; it makes sense to ''inherit'' from an iterator, because they cannot have more than one active iterator.&lt;br /&gt;
&lt;br /&gt;
On the other side, a ''container'' is a finite storage of values. Containers are deliberately confined to finite structures and understood real, physical storage. Infinite structures, instead, are usually represented as functions or mechanisms that are external to a program. Most of the time we can only access their elements (not add or remove) and for this purpose we have observers: maps and iterators (the latter in the infinite case are called ''streams'').&lt;br /&gt;
&lt;br /&gt;
Containers may be classified based on different means of modification, but previous experience shows that a complete and clean classification here is impossible (there are two many kinds of modification, basically one per &amp;quot;concrete&amp;quot; data structure). So concrete data structures mostly just inherit directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;. There is one exception: &amp;lt;e&amp;gt;SEQUENCE&amp;lt;/e&amp;gt;, which represents a sequence of values accessible by indices from a continuous interval. It serves as a common ancestor for ARRAY and LIST and factors out their common search and replacement mechanisms.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies (according to connectedness). The first one is a hierarchy of containers and maps. Note: dash-bordered ovals stand for classes that might be included in the library, but are not the first priority of the developers.  &lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
The second one is a hierarchy of streams and iterators.&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
===Comparison criteria===&lt;br /&gt;
Another important design decision for a data structures library is how to represent and modify comparison criteria for container elements.&lt;br /&gt;
Adjustable comparison criterion is used is search operations and to define the uniqueness property in sets and tables (uniqueness of keys).&lt;br /&gt;
# Classic EiffelBase uses the boolean &amp;lt;e&amp;gt;object_comparison&amp;lt;/e&amp;gt; attribute in &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt; for this purpose.&lt;br /&gt;
# Gobo.structures uses another approach: storing equivalence as an object of a specific class, which can be redefined by the user to implement an arbitrary equalivalence relation.&lt;br /&gt;
# A similar approach would be to use agents to store the equalivalence relation (no need to create classes). The downside is that agents do not serialize well.&lt;br /&gt;
# Another approach is to make &amp;lt;e&amp;gt;has (x: G)&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;search (x: G)&amp;lt;/e&amp;gt; always use &amp;lt;e&amp;gt;=&amp;lt;/e&amp;gt;, but also introduce &amp;lt;e&amp;gt;exists (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;satisfy (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt;. This is more flexible (better fits cases when the predicate is not an equivalence), but duplicates the number of search features and doesn't solve the problem with sets.&lt;br /&gt;
&lt;br /&gt;
Additional question (if the comparison criterion is stored in the container) is whether it can be changed during the object lifetime. A well known practice is that in sets it is not allowed to change if the set is not empty. This gives rise to &amp;lt;e&amp;gt;changeable_comparison_criterion&amp;lt;/e&amp;gt; query in CONTAINER.&lt;br /&gt;
Note that for most set and table implementations (hashed, sorted) the comparison critearion is defined by the corresponding hash function, order, etc. and cannot be modified arbitrary even when the set or table is empty.&lt;br /&gt;
&lt;br /&gt;
The strategy chosen in EiffelBase2 is to treat differently comparison criteria on which a set or a table is based and ones just used for search. For the first the Gobo approach is taken (2 in the list above), because it is more flexible than in EiffelBase, as we can use whatever equivalence relation we want instead of just &amp;lt;e&amp;gt;is_equal&amp;lt;/e&amp;gt; (useful for library classes). Moreover, the equivalence relation is passed as an argument to the creation procedure and cannot be changed afterward. &lt;br /&gt;
&lt;br /&gt;
For search operations the approach 4 is taken, because it doesn't clutter the container state with properties that don't pertain to the container itself, but to specific search operations.&lt;br /&gt;
&lt;br /&gt;
===Indexing===&lt;br /&gt;
The current version of EiffelBase2 is using the same policy for indexing as the one used in the classic EiffelBase: indexing of lists (and iterators) always starts from 1, whereas for arrays the starting index can be set to an arbitrary value. However, during the code review in the Chair of Software Engineering (17.03.2010) is was decided that the possibility to start arrays from an arbitrary index is not crucial and is used very rarely, but complicates the API. Thus it will probably be changed in future so that indices of arrays, like those of other indexed data structures, always start at 1.&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
EiffelBase2 is specified using the ''model-based contracts'' specification method. This method prescribes that each class define a ''model'' - a mathematical object that represents explicitly its abstract state space. The model of a class is expressed as tuple of one or more predefined mathematical objects: booleans, integers, sets, relations, maps, sequences or bags. We also introduce a special mathematical sort for object IDs (references).&lt;br /&gt;
&lt;br /&gt;
Such mathematical objects in the program are represented by ''model classes'', which are immutable and thus are straightforward translations of mathematical definitions. The MML library, which is a part of EiffelBase2 contains model classes for sets, relations, maps, sequences and bags. Boolean and integer components of models are represented by standard classes &amp;lt;c&amp;gt;BOOLEAN&amp;lt;/c&amp;gt; and &amp;lt;c&amp;gt;INTEGER&amp;lt;/c&amp;gt;. Finally, arbitrary reference classes can be used as model components to denote the mathematical sort of references.&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
Development of EiffelBase has started as a project at ETH Zurich; see the [http://eiffelbase2.origo.ethz.ch/ project page]. Documentation and other material will soon be transferred to the present page.&lt;br /&gt;
&lt;br /&gt;
===ToDo list===&lt;br /&gt;
Below you can see a list of most important changes planned for EiffelBase2.&lt;br /&gt;
* Test extensively with AutoTest.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;HASH_TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;PREORDER_ITERATOR&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;POSTORDER_ITERATOR&amp;lt;/e&amp;gt; to traverse binaries in pre- and postorder.&lt;br /&gt;
* Iterator management: currently the situation when a container is modified through one iterator while it's being traversed with another is not handled anyhow.&lt;br /&gt;
* Finish the implementation of the MML library.&lt;br /&gt;
* Rewrite loops using the &amp;lt;e&amp;gt;accross&amp;lt;/e&amp;gt; where appropriate.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;STANDARD_INPUT&amp;lt;/e&amp;gt; streams.&lt;br /&gt;
* Add an iterator over keys for &amp;lt;e&amp;gt;TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Make the library void-safe.&lt;br /&gt;
* Implement more efficient data structures: e.g., tables with fast lookup both ways, heaps, skip lists, treaps, etc.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13795</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13795"/>
				<updated>2010-04-23T16:17:49Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Indexing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2, currently under development, is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library (&amp;quot;Classic EiffelBase&amp;quot; in this document), which has for many years played a central role in Eiffel development. &lt;br /&gt;
&lt;br /&gt;
==Design goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Full contracts. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
*As in Classic EiffelBase, application of a systematic classification (a theory) of fundamental data structures.&lt;br /&gt;
&lt;br /&gt;
*Full traversal mechanisms, based on external cursors (with internal cursors also provided when useful).&lt;br /&gt;
&lt;br /&gt;
*Client-interface compatibility with corresponding classes in Classic EiffelBase, whenever it does not conflict with the preceding goals.&lt;br /&gt;
&lt;br /&gt;
==Design overview==&lt;br /&gt;
===Traversal mechanisms and classification criteria===&lt;br /&gt;
A design decision that significantly influenced the architecture of the library is using external iterators to traverse containers as apposed to internal ones available in classic EiffelBase.&lt;br /&gt;
In the design inspired by external iterators we found it natural to separate ''containers'' (with their measurements and modification means) from interfaces to access elements of containers, here called ''observers''.&lt;br /&gt;
&lt;br /&gt;
On the observer side we distinguish ''maps'' (with the defining property &amp;quot;accessing elements by unique keys&amp;quot;) and iterators (providing linear traversal). An observer can be either ''used'' by a container (as a supplier) or ''inherited'' by it. The first case produces an external access mechanism and is useful when multiple instances of an observer for the same container can exist at the same time; the second case results in an internal access mechanism and allows only one instance of an observer per container at a time. In the rest of the library maps are mostly inherited and iterators are mostly used, but this is not enforced by the design. For infinite sequences like &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; it makes sense to ''inherit'' from an iterator, because they cannot have more than one active iterator.&lt;br /&gt;
&lt;br /&gt;
On the other side, a ''container'' is a finite storage of values. Containers are deliberately confined to finite structures and understood real, physical storage. Infinite structures, instead, are usually represented as functions or mechanisms that are external to a program. Most of the time we can only access their elements (not add or remove) and for this purpose we have observers: maps and iterators (the latter in the infinite case are called ''streams'').&lt;br /&gt;
&lt;br /&gt;
Containers may be classified based on different means of modification, but previous experience shows that a complete and clean classification here is impossible (there are two many kinds of modification, basically one per &amp;quot;concrete&amp;quot; data structure). So concrete data structures mostly just inherit directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;. There is one exception: &amp;lt;e&amp;gt;SEQUENCE&amp;lt;/e&amp;gt;, which represents a sequence of values accessible by indices from a continuous interval. It serves as a common ancestor for ARRAY and LIST and factors out their common search and replacement mechanisms.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies (according to connectedness). The first one is a hierarchy of containers and maps. Note: dash-bordered ovals stand for classes that might be included in the library, but are not the first priority of the developers.  &lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
The second one is a hierarchy of streams and iterators.&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
===Comparison criteria===&lt;br /&gt;
Another important design decision for a data structures library is how to represent and modify comparison criteria for container elements.&lt;br /&gt;
Adjustable comparison criterion is used is search operations and to define the uniqueness property in sets and tables (uniqueness of keys).&lt;br /&gt;
# Classic EiffelBase uses the boolean &amp;lt;e&amp;gt;object_comparison&amp;lt;/e&amp;gt; attribute in &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt; for this purpose.&lt;br /&gt;
# Gobo.structures uses another approach: storing equivalence as an object of a specific class, which can be redefined by the user to implement an arbitrary equalivalence relation.&lt;br /&gt;
# A similar approach would be to use agents to store the equalivalence relation (no need to create classes). The downside is that agents do not serialize well.&lt;br /&gt;
# Another approach is to make &amp;lt;e&amp;gt;has (x: G)&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;search (x: G)&amp;lt;/e&amp;gt; always use &amp;lt;e&amp;gt;=&amp;lt;/e&amp;gt;, but also introduce &amp;lt;e&amp;gt;exists (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;satisfy (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt;. This is more flexible (better fits cases when the predicate is not an equivalence), but duplicates the number of search features and doesn't solve the problem with sets.&lt;br /&gt;
&lt;br /&gt;
Additional question (if the comparison criterion is stored in the container) is whether it can be changed during the object lifetime. A well known practice is that in sets it is not allowed to change if the set is not empty. This gives rise to &amp;lt;e&amp;gt;changeable_comparison_criterion&amp;lt;/e&amp;gt; query in CONTAINER.&lt;br /&gt;
Note that for most set and table implementations (hashed, sorted) the comparison critearion is defined by the corresponding hash function, order, etc. and cannot be modified arbitrary even when the set or table is empty.&lt;br /&gt;
&lt;br /&gt;
The strategy chosen in EiffelBase2 is to treat differently comparison criteria on which a set or a table is based and ones just used for search. For the first the Gobo approach is taken (2 in the list above), because it is more flexible than in EiffelBase, as we can use whatever equivalence relation we want instead of just &amp;lt;e&amp;gt;is_equal&amp;lt;/e&amp;gt; (useful for library classes). Moreover, the equivalence relation is passed as an argument to the creation procedure and cannot be changed afterward. &lt;br /&gt;
&lt;br /&gt;
For search operations the approach 4 is taken, because it doesn't clutter the container state with properties that don't pertain to the container itself, but to specific search operations.&lt;br /&gt;
&lt;br /&gt;
===Indexing===&lt;br /&gt;
The current version of EiffelBase2 is using the same policy for indexing as the one used in the classic EiffelBase: indexing of lists (and iterators) always starts from 1, whereas for arrays the starting index can be set to an arbitrary value. However, during the code review in the Chair of Software Engineering (17.03.2010) is was decided that the possibility to start arrays from an arbitrary index is not crucial and is used very rarely, but complicates the API. Thus it will probably be changed in future so that indices of arrays, like those of other indexed data structures, always start at 1.&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
Development of EiffelBase has started as a project at ETH Zurich; see the [http://eiffelbase2.origo.ethz.ch/ project page]. Documentation and other material will soon be transferred to the present page.&lt;br /&gt;
&lt;br /&gt;
===ToDo list===&lt;br /&gt;
Below you can see a list of most important changes planned for EiffelBase2.&lt;br /&gt;
* Test extensively with AutoTest.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;HASH_TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;PREORDER_ITERATOR&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;POSTORDER_ITERATOR&amp;lt;/e&amp;gt; to traverse binaries in pre- and postorder.&lt;br /&gt;
* Iterator management: currently the situation when a container is modified through one iterator while it's being traversed with another is not handled anyhow.&lt;br /&gt;
* Finish the implementation of the MML library.&lt;br /&gt;
* Rewrite loops using the &amp;lt;e&amp;gt;accross&amp;lt;/e&amp;gt; where appropriate.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;STANDARD_INPUT&amp;lt;/e&amp;gt; streams.&lt;br /&gt;
* Add an iterator over keys for &amp;lt;e&amp;gt;TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Make the library void-safe.&lt;br /&gt;
* Implement more efficient data structures: e.g., tables with fast lookup both ways, heaps, skip lists, treaps, etc.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13794</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13794"/>
				<updated>2010-04-23T16:16:41Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Design overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2, currently under development, is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library (&amp;quot;Classic EiffelBase&amp;quot; in this document), which has for many years played a central role in Eiffel development. &lt;br /&gt;
&lt;br /&gt;
==Design goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Full contracts. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
*As in Classic EiffelBase, application of a systematic classification (a theory) of fundamental data structures.&lt;br /&gt;
&lt;br /&gt;
*Full traversal mechanisms, based on external cursors (with internal cursors also provided when useful).&lt;br /&gt;
&lt;br /&gt;
*Client-interface compatibility with corresponding classes in Classic EiffelBase, whenever it does not conflict with the preceding goals.&lt;br /&gt;
&lt;br /&gt;
==Design overview==&lt;br /&gt;
===Traversal mechanisms and classification criteria===&lt;br /&gt;
A design decision that significantly influenced the architecture of the library is using external iterators to traverse containers as apposed to internal ones available in classic EiffelBase.&lt;br /&gt;
In the design inspired by external iterators we found it natural to separate ''containers'' (with their measurements and modification means) from interfaces to access elements of containers, here called ''observers''.&lt;br /&gt;
&lt;br /&gt;
On the observer side we distinguish ''maps'' (with the defining property &amp;quot;accessing elements by unique keys&amp;quot;) and iterators (providing linear traversal). An observer can be either ''used'' by a container (as a supplier) or ''inherited'' by it. The first case produces an external access mechanism and is useful when multiple instances of an observer for the same container can exist at the same time; the second case results in an internal access mechanism and allows only one instance of an observer per container at a time. In the rest of the library maps are mostly inherited and iterators are mostly used, but this is not enforced by the design. For infinite sequences like &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; it makes sense to ''inherit'' from an iterator, because they cannot have more than one active iterator.&lt;br /&gt;
&lt;br /&gt;
On the other side, a ''container'' is a finite storage of values. Containers are deliberately confined to finite structures and understood real, physical storage. Infinite structures, instead, are usually represented as functions or mechanisms that are external to a program. Most of the time we can only access their elements (not add or remove) and for this purpose we have observers: maps and iterators (the latter in the infinite case are called ''streams'').&lt;br /&gt;
&lt;br /&gt;
Containers may be classified based on different means of modification, but previous experience shows that a complete and clean classification here is impossible (there are two many kinds of modification, basically one per &amp;quot;concrete&amp;quot; data structure). So concrete data structures mostly just inherit directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;. There is one exception: &amp;lt;e&amp;gt;SEQUENCE&amp;lt;/e&amp;gt;, which represents a sequence of values accessible by indices from a continuous interval. It serves as a common ancestor for ARRAY and LIST and factors out their common search and replacement mechanisms.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies (according to connectedness). The first one is a hierarchy of containers and maps. Note: dash-bordered ovals stand for classes that might be included in the library, but are not the first priority of the developers.  &lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
The second one is a hierarchy of streams and iterators.&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
===Comparison criteria===&lt;br /&gt;
Another important design decision for a data structures library is how to represent and modify comparison criteria for container elements.&lt;br /&gt;
Adjustable comparison criterion is used is search operations and to define the uniqueness property in sets and tables (uniqueness of keys).&lt;br /&gt;
# Classic EiffelBase uses the boolean &amp;lt;e&amp;gt;object_comparison&amp;lt;/e&amp;gt; attribute in &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt; for this purpose.&lt;br /&gt;
# Gobo.structures uses another approach: storing equivalence as an object of a specific class, which can be redefined by the user to implement an arbitrary equalivalence relation.&lt;br /&gt;
# A similar approach would be to use agents to store the equalivalence relation (no need to create classes). The downside is that agents do not serialize well.&lt;br /&gt;
# Another approach is to make &amp;lt;e&amp;gt;has (x: G)&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;search (x: G)&amp;lt;/e&amp;gt; always use &amp;lt;e&amp;gt;=&amp;lt;/e&amp;gt;, but also introduce &amp;lt;e&amp;gt;exists (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;satisfy (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt;. This is more flexible (better fits cases when the predicate is not an equivalence), but duplicates the number of search features and doesn't solve the problem with sets.&lt;br /&gt;
&lt;br /&gt;
Additional question (if the comparison criterion is stored in the container) is whether it can be changed during the object lifetime. A well known practice is that in sets it is not allowed to change if the set is not empty. This gives rise to &amp;lt;e&amp;gt;changeable_comparison_criterion&amp;lt;/e&amp;gt; query in CONTAINER.&lt;br /&gt;
Note that for most set and table implementations (hashed, sorted) the comparison critearion is defined by the corresponding hash function, order, etc. and cannot be modified arbitrary even when the set or table is empty.&lt;br /&gt;
&lt;br /&gt;
The strategy chosen in EiffelBase2 is to treat differently comparison criteria on which a set or a table is based and ones just used for search. For the first the Gobo approach is taken (2 in the list above), because it is more flexible than in EiffelBase, as we can use whatever equivalence relation we want instead of just &amp;lt;e&amp;gt;is_equal&amp;lt;/e&amp;gt; (useful for library classes). Moreover, the equivalence relation is passed as an argument to the creation procedure and cannot be changed afterward. &lt;br /&gt;
&lt;br /&gt;
For search operations the approach 4 is taken, because it doesn't clutter the container state with properties that don't pertain to the container itself, but to specific search operations.&lt;br /&gt;
&lt;br /&gt;
===Indexing===&lt;br /&gt;
The current version of EiffelBase2 is using the same policy for indexing as the one used in the classic EiffelBase: indexing of lists (and iterators) always starts from 1, whereas for arrays the starting index can be set to an arbitrary value. However, during the code review in the Chair of Software Engineering (17.03.2010) is was decided that the possibility to start arrays from an arbitrary index is not crucial and is used very rarely, but complicates the API. Thus it will probably be changed in future so that array indexing, like in other indexed data structures, always starts at 1.&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
Development of EiffelBase has started as a project at ETH Zurich; see the [http://eiffelbase2.origo.ethz.ch/ project page]. Documentation and other material will soon be transferred to the present page.&lt;br /&gt;
&lt;br /&gt;
===ToDo list===&lt;br /&gt;
Below you can see a list of most important changes planned for EiffelBase2.&lt;br /&gt;
* Test extensively with AutoTest.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;HASH_TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;PREORDER_ITERATOR&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;POSTORDER_ITERATOR&amp;lt;/e&amp;gt; to traverse binaries in pre- and postorder.&lt;br /&gt;
* Iterator management: currently the situation when a container is modified through one iterator while it's being traversed with another is not handled anyhow.&lt;br /&gt;
* Finish the implementation of the MML library.&lt;br /&gt;
* Rewrite loops using the &amp;lt;e&amp;gt;accross&amp;lt;/e&amp;gt; where appropriate.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;STANDARD_INPUT&amp;lt;/e&amp;gt; streams.&lt;br /&gt;
* Add an iterator over keys for &amp;lt;e&amp;gt;TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Make the library void-safe.&lt;br /&gt;
* Implement more efficient data structures: e.g., tables with fast lookup both ways, heaps, skip lists, treaps, etc.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13793</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13793"/>
				<updated>2010-04-23T16:03:37Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Status and roadmap */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2, currently under development, is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library (&amp;quot;Classic EiffelBase&amp;quot; in this document), which has for many years played a central role in Eiffel development. &lt;br /&gt;
&lt;br /&gt;
==Design goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Full contracts. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
*As in Classic EiffelBase, application of a systematic classification (a theory) of fundamental data structures.&lt;br /&gt;
&lt;br /&gt;
*Full traversal mechanisms, based on external cursors (with internal cursors also provided when useful).&lt;br /&gt;
&lt;br /&gt;
*Client-interface compatibility with corresponding classes in Classic EiffelBase, whenever it does not conflict with the preceding goals.&lt;br /&gt;
&lt;br /&gt;
==Design overview==&lt;br /&gt;
===Traversal mechanisms and classification criteria===&lt;br /&gt;
A design decision that significantly influenced the architecture of the library is using external iterators to traverse containers as apposed to internal ones available in classic EiffelBase.&lt;br /&gt;
In the design inspired by external iterators we found it natural to separate ''containers'' (with their measurements and modification means) from interfaces to access elements of containers, here called ''observers''.&lt;br /&gt;
&lt;br /&gt;
On the observer side we distinguish ''maps'' (with the defining property &amp;quot;accessing elements by unique keys&amp;quot;) and iterators (providing linear traversal). An observer can be either ''used'' by a container (as a supplier) or ''inherited'' by it. The first case produces an external access mechanism and is useful when multiple instances of an observer for the same container can exist at the same time; the second case results in an internal access mechanism and allows only one instance of an observer per container at a time. In the rest of the library maps are mostly inherited and iterators are mostly used, but this is not enforced by the design. For infinite sequences like &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; it makes sense to ''inherit'' from an iterator, because they cannot have more than one active iterator.&lt;br /&gt;
&lt;br /&gt;
On the other side, a ''container'' is a finite storage of values. Containers are deliberately confined to finite structures and understood real, physical storage. Infinite structures, instead, are usually represented as functions or mechanisms that are external to a program. Most of the time we can only access their elements (not add or remove) and for this purpose we have observers: maps and iterators (the latter in the infinite case are called ''streams'').&lt;br /&gt;
&lt;br /&gt;
Containers may be classified based on different means of modification, but previous experience shows that a complete and clean classification here is impossible (there are two many kinds of modification, basically one per &amp;quot;concrete&amp;quot; data structure). So concrete data structures mostly just inherit directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;. There is one exception: &amp;lt;e&amp;gt;SEQUENCE&amp;lt;/e&amp;gt;, which represents a sequence of values accessible by indices from a continuous interval. It serves as a common ancestor for ARRAY and LIST and factors out their common search and replacement mechanisms.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies (according to connectedness). The first one is a hierarchy of containers and maps. Note: dash-bordered ovals stand for classes that might be included in the library, but are not the first priority of the developers.  &lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
The second one is a hierarchy of streams and iterators.&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
===Comparison criteria===&lt;br /&gt;
Another important design decision for a data structures library is how to represent and modify comparison criteria for container elements.&lt;br /&gt;
Adjustable comparison criterion is used is search operations and to define the uniqueness property in sets and tables (uniqueness of keys).&lt;br /&gt;
# Classic EiffelBase uses the boolean &amp;lt;e&amp;gt;object_comparison&amp;lt;/e&amp;gt; attribute in &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt; for this purpose.&lt;br /&gt;
# Gobo.structures uses another approach: storing equivalence as an object of a specific class, which can be redefined by the user to implement an arbitrary equalivalence relation.&lt;br /&gt;
# A similar approach would be to use agents to store the equalivalence relation (no need to create classes). The downside is that agents do not serialize well.&lt;br /&gt;
# Another approach is to make &amp;lt;e&amp;gt;has (x: G)&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;search (x: G)&amp;lt;/e&amp;gt; always use &amp;lt;e&amp;gt;=&amp;lt;/e&amp;gt;, but also introduce &amp;lt;e&amp;gt;exists (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;satisfy (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt;. This is more flexible (better fits cases when the predicate is not an equivalence), but duplicates the number of search features and doesn't solve the problem with sets.&lt;br /&gt;
&lt;br /&gt;
Additional question (if the comparison criterion is stored in the container) is whether it can be changed during the object lifetime. A well known practice is that in sets it is not allowed to change if the set is not empty. This gives rise to &amp;lt;e&amp;gt;changeable_comparison_criterion&amp;lt;/e&amp;gt; query in CONTAINER.&lt;br /&gt;
Note that for most set and table implementations (hashed, sorted) the comparison critearion is defined by the corresponding hash function, order, etc. and cannot be modified arbitrary even when the set or table is empty.&lt;br /&gt;
&lt;br /&gt;
The strategy chosen in EiffelBase2 is to treat differently comparison criteria on which a set or a table is based and ones just used for search. For the first the Gobo approach is taken (2 in the list above), because it is more flexible than in EiffelBase, as we can use whatever equivalence relation we want instead of just &amp;lt;e&amp;gt;is_equal&amp;lt;/e&amp;gt; (useful for library classes). Moreover, the equivalence relation is passed as an argument to the creation procedure and cannot be changed afterward. &lt;br /&gt;
&lt;br /&gt;
For search operations the approach 4 is taken, because it doesn't clutter the container state with properties that don't pertain to the container itself, but to specific search operations.&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
Development of EiffelBase has started as a project at ETH Zurich; see the [http://eiffelbase2.origo.ethz.ch/ project page]. Documentation and other material will soon be transferred to the present page.&lt;br /&gt;
&lt;br /&gt;
===ToDo list===&lt;br /&gt;
Below you can see a list of most important changes planned for EiffelBase2.&lt;br /&gt;
* Test extensively with AutoTest.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;HASH_SET&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;HASH_TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;PREORDER_ITERATOR&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;POSTORDER_ITERATOR&amp;lt;/e&amp;gt; to traverse binaries in pre- and postorder.&lt;br /&gt;
* Iterator management: currently the situation when a container is modified through one iterator while it's being traversed with another is not handled anyhow.&lt;br /&gt;
* Finish the implementation of the MML library.&lt;br /&gt;
* Rewrite loops using the &amp;lt;e&amp;gt;accross&amp;lt;/e&amp;gt; where appropriate.&lt;br /&gt;
* Implement &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;STANDARD_INPUT&amp;lt;/e&amp;gt; streams.&lt;br /&gt;
* Add an iterator over keys for &amp;lt;e&amp;gt;TABLE&amp;lt;/e&amp;gt;.&lt;br /&gt;
* Make the library void-safe.&lt;br /&gt;
* Implement more efficient data structures: e.g., tables with fast lookup both ways, heaps, skip lists, treaps, etc.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13792</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13792"/>
				<updated>2010-04-23T14:48:09Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Design overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2, currently under development, is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library (&amp;quot;Classic EiffelBase&amp;quot; in this document), which has for many years played a central role in Eiffel development. &lt;br /&gt;
&lt;br /&gt;
==Design goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Full contracts. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
*As in Classic EiffelBase, application of a systematic classification (a theory) of fundamental data structures.&lt;br /&gt;
&lt;br /&gt;
*Full traversal mechanisms, based on external cursors (with internal cursors also provided when useful).&lt;br /&gt;
&lt;br /&gt;
*Client-interface compatibility with corresponding classes in Classic EiffelBase, whenever it does not conflict with the preceding goals.&lt;br /&gt;
&lt;br /&gt;
==Design overview==&lt;br /&gt;
===Traversal mechanisms and classification criteria===&lt;br /&gt;
A design decision that significantly influenced the architecture of the library is using external iterators to traverse containers as apposed to internal ones available in classic EiffelBase.&lt;br /&gt;
In the design inspired by external iterators we found it natural to separate ''containers'' (with their measurements and modification means) from interfaces to access elements of containers, here called ''observers''.&lt;br /&gt;
&lt;br /&gt;
On the observer side we distinguish ''maps'' (with the defining property &amp;quot;accessing elements by unique keys&amp;quot;) and iterators (providing linear traversal). An observer can be either ''used'' by a container (as a supplier) or ''inherited'' by it. The first case produces an external access mechanism and is useful when multiple instances of an observer for the same container can exist at the same time; the second case results in an internal access mechanism and allows only one instance of an observer per container at a time. In the rest of the library maps are mostly inherited and iterators are mostly used, but this is not enforced by the design. For infinite sequences like &amp;lt;e&amp;gt;RANDOM&amp;lt;/e&amp;gt; it makes sense to ''inherit'' from an iterator, because they cannot have more than one active iterator.&lt;br /&gt;
&lt;br /&gt;
On the other side, a ''container'' is a finite storage of values. Containers are deliberately confined to finite structures and understood real, physical storage. Infinite structures, instead, are usually represented as functions or mechanisms that are external to a program. Most of the time we can only access their elements (not add or remove) and for this purpose we have observers: maps and iterators (the latter in the infinite case are called ''streams'').&lt;br /&gt;
&lt;br /&gt;
Containers may be classified based on different means of modification, but previous experience shows that a complete and clean classification here is impossible (there are two many kinds of modification, basically one per &amp;quot;concrete&amp;quot; data structure). So concrete data structures mostly just inherit directly from &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt;. There is one exception: &amp;lt;e&amp;gt;SEQUENCE&amp;lt;/e&amp;gt;, which represents a sequence of values accessible by indices from a continuous interval. It serves as a common ancestor for ARRAY and LIST and factors out their common search and replacement mechanisms.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies (according to connectedness). The first one is a hierarchy of containers and maps. Note: dash-bordered ovals stand for classes that might be included in the library, but are not the first priority of the developers.  &lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
The second one is a hierarchy of streams and iterators.&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
===Comparison criteria===&lt;br /&gt;
Another important design decision for a data structures library is how to represent and modify comparison criteria for container elements.&lt;br /&gt;
Adjustable comparison criterion is used is search operations and to define the uniqueness property in sets and tables (uniqueness of keys).&lt;br /&gt;
# Classic EiffelBase uses the boolean &amp;lt;e&amp;gt;object_comparison&amp;lt;/e&amp;gt; attribute in &amp;lt;e&amp;gt;CONTAINER&amp;lt;/e&amp;gt; for this purpose.&lt;br /&gt;
# Gobo.structures uses another approach: storing equivalence as an object of a specific class, which can be redefined by the user to implement an arbitrary equalivalence relation.&lt;br /&gt;
# A similar approach would be to use agents to store the equalivalence relation (no need to create classes). The downside is that agents do not serialize well.&lt;br /&gt;
# Another approach is to make &amp;lt;e&amp;gt;has (x: G)&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;search (x: G)&amp;lt;/e&amp;gt; always use &amp;lt;e&amp;gt;=&amp;lt;/e&amp;gt;, but also introduce &amp;lt;e&amp;gt;exists (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt; and &amp;lt;e&amp;gt;satisfy (p: PREDICATE [ANY, TUPLE [G]])&amp;lt;/e&amp;gt;. This is more flexible (better fits cases when the predicate is not an equivalence), but duplicates the number of search features and doesn't solve the problem with sets.&lt;br /&gt;
&lt;br /&gt;
Additional question (if the comparison criterion is stored in the container) is whether it can be changed during the object lifetime. A well known practice is that in sets it is not allowed to change if the set is not empty. This gives rise to &amp;lt;e&amp;gt;changeable_comparison_criterion&amp;lt;/e&amp;gt; query in CONTAINER.&lt;br /&gt;
Note that for most set and table implementations (hashed, sorted) the comparison critearion is defined by the corresponding hash function, order, etc. and cannot be modified arbitrary even when the set or table is empty.&lt;br /&gt;
&lt;br /&gt;
The strategy chosen in EiffelBase2 is to treat differently comparison criteria on which a set or a table is based and ones just used for search. For the first the Gobo approach is taken (2 in the list above), because it is more flexible than in EiffelBase, as we can use whatever equivalence relation we want instead of just &amp;lt;e&amp;gt;is_equal&amp;lt;/e&amp;gt; (useful for library classes). Moreover, the equivalence relation is passed as an argument to the creation procedure and cannot be changed afterward. &lt;br /&gt;
&lt;br /&gt;
For search operations the approach 4 is taken, because it doesn't clutter the container state with properties that don't pertain to the container itself, but to specific search operations.&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
Development of EiffelBase has started as a project at ETH Zurich; see the [http://eiffelbase2.origo.ethz.ch/ project page]. Documentation and other material will soon be transferred to the present page.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13791</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13791"/>
				<updated>2010-04-23T13:19:52Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Design overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2, currently under development, is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library (&amp;quot;Classic EiffelBase&amp;quot; in this document), which has for many years played a central role in Eiffel development. &lt;br /&gt;
&lt;br /&gt;
==Design goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Full contracts. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
*As in Classic EiffelBase, application of a systematic classification (a theory) of fundamental data structures.&lt;br /&gt;
&lt;br /&gt;
*Full traversal mechanisms, based on external cursors (with internal cursors also provided when useful).&lt;br /&gt;
&lt;br /&gt;
*Client-interface compatibility with corresponding classes in Classic EiffelBase, whenever it does not conflict with the preceding goals.&lt;br /&gt;
&lt;br /&gt;
==Design overview==&lt;br /&gt;
A design decision that significantly influenced the architecture of the library is using external iterators to traverse containers as apposed to internal ones available in classic EiffelBase.&lt;br /&gt;
In the design inspired by external iterators we found it natural to separate ''containers'' (with their measurements and modification means) from interfaces to access elements of containers, here called ''observers''.&lt;br /&gt;
&lt;br /&gt;
On the observer side we distinguish ''maps'' (with the defining property &amp;quot;accessing elements by unique keys&amp;quot;) and iterators (providing linear traversal). An observer can be either ''used'' by a container (as a supplier) or ''inherited'' by it. The first case produces an external access mechanism and is useful when multiple instances of an observer for the same container can exist at the same time; the second case results in an internal acess mechanism and allows only one instance of an observer per container at a time. In the rest of the library maps are mostly inherited and iterators are mostly used, but this is not enforced by the design. For infinite sequences like RANDOM it makes sense to ''inherit'' from an iterator, because they cannot have more than one active iterator.&lt;br /&gt;
&lt;br /&gt;
On the other side, a ''container'' is a finite storage of values. Containers are deliberately confined to finite structures and understood real, physical storage. Infinite structures, instead, are usually represented as functions or mechanisms that are external to a program. Most of the time we can only access their elements (not add or remove) and for this purpose we have observers: maps and iterators (the latter in the infinite case are called ''streams'').&lt;br /&gt;
&lt;br /&gt;
Containers may be classified based on different means of modification, but previous experience shows that a complete and clean classification here is impossible (there are two many kinds of modification, basically one per &amp;quot;concrete&amp;quot; data structure). So concrete data structures mostly just inherit directly from CONTAINER. There is one exception: SEQUENCE, which represents a sequence of values accessible by indices from a continuous interval. It serves as a common ancestor for ARRAY and LIST and factors out their common search and replacement mechanisms.&lt;br /&gt;
&lt;br /&gt;
Below you can find the class diagram of EiffelBase2, split into two hierarchies (according to connectedness). The first one is a hierarchy of containers and maps. Note: dash-bordered ovals stand for classes that might be included in the library, but are not the first priority of the developers.  &lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|none|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
The second one is a hierarchy of streams and iterators.&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|none|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
Development of EiffelBase has started as a project at ETH Zurich; see the [http://eiffelbase2.origo.ethz.ch/ project page]. Documentation and other material will soon be transferred to the present page.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13790</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13790"/>
				<updated>2010-04-23T12:51:43Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2, currently under development, is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library (&amp;quot;Classic EiffelBase&amp;quot; in this document), which has for many years played a central role in Eiffel development. &lt;br /&gt;
&lt;br /&gt;
==Design goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Full contracts. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
*As in Classic EiffelBase, application of a systematic classification (a theory) of fundamental data structures.&lt;br /&gt;
&lt;br /&gt;
*Full traversal mechanisms, based on external cursors (with internal cursors also provided when useful).&lt;br /&gt;
&lt;br /&gt;
*Client-interface compatibility with corresponding classes in Classic EiffelBase, whenever it does not conflict with the preceding goals.&lt;br /&gt;
&lt;br /&gt;
==Design overview==&lt;br /&gt;
[[Image:eb2_container.png|800px|frameless|left|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
[[Image:eb2_iterator.png|800px|frameless|left|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
Development of EiffelBase has started as a project at ETH Zurich; see the [http://eiffelbase2.origo.ethz.ch/ project page]. Documentation and other material will soon be transferred to the present page.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13789</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13789"/>
				<updated>2010-04-23T12:49:05Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Design overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2, currently under development, is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library (&amp;quot;Classic EiffelBase&amp;quot; in this document), which has for many years played a central role in Eiffel development. &lt;br /&gt;
&lt;br /&gt;
==Design goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Full contracts. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
*As in Classic EiffelBase, application of a systematic classification (a theory) of fundamental data structures.&lt;br /&gt;
&lt;br /&gt;
*Full traversal mechanisms, based on external cursors (with internal cursors also provided when useful).&lt;br /&gt;
&lt;br /&gt;
*Client-interface compatibility with corresponding classes in Classic EiffelBase, whenever it does not conflict with the preceding goals.&lt;br /&gt;
&lt;br /&gt;
==Design overview==&lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|left|Container class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|left|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
Development of EiffelBase has started as a project at ETH Zurich; see the [http://eiffelbase2.origo.ethz.ch/ project page]. Documentation and other material will soon be transferred to the present page.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13788</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13788"/>
				<updated>2010-04-23T12:48:34Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Design overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2, currently under development, is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library (&amp;quot;Classic EiffelBase&amp;quot; in this document), which has for many years played a central role in Eiffel development. &lt;br /&gt;
&lt;br /&gt;
==Design goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Full contracts. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
*As in Classic EiffelBase, application of a systematic classification (a theory) of fundamental data structures.&lt;br /&gt;
&lt;br /&gt;
*Full traversal mechanisms, based on external cursors (with internal cursors also provided when useful).&lt;br /&gt;
&lt;br /&gt;
*Client-interface compatibility with corresponding classes in Classic EiffelBase, whenever it does not conflict with the preceding goals.&lt;br /&gt;
&lt;br /&gt;
==Design overview==&lt;br /&gt;
[[Image:eb2_container.png|800px|thumb|left|Container class hierarchy]]&lt;br /&gt;
[[Image:eb2_iterator.png|800px|thumb|left|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
Development of EiffelBase has started as a project at ETH Zurich; see the [http://eiffelbase2.origo.ethz.ch/ project page]. Documentation and other material will soon be transferred to the present page.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=File:Eb2_iterator.png&amp;diff=13787</id>
		<title>File:Eb2 iterator.png</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=File:Eb2_iterator.png&amp;diff=13787"/>
				<updated>2010-04-23T12:47:03Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: Class diagram of the iterator classes in EiffelBase2 library.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Class diagram of the iterator classes in EiffelBase2 library.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13786</id>
		<title>EiffelBase2</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=EiffelBase2&amp;diff=13786"/>
				<updated>2010-04-23T12:46:32Z</updated>
		
		<summary type="html">&lt;p&gt;Kenga: /* Design overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
EiffelBase2, currently under development, is a general-purpose data structures library for Eiffel. It is intended as the future replacement for the [[EiffelBase]] library (&amp;quot;Classic EiffelBase&amp;quot; in this document), which has for many years played a central role in Eiffel development. &lt;br /&gt;
&lt;br /&gt;
==Design goals==&lt;br /&gt;
&lt;br /&gt;
The design goals for EiffelBase2 are:&lt;br /&gt;
&lt;br /&gt;
*Verifiability. The library is designed to allow proofs of correctness.&lt;br /&gt;
&lt;br /&gt;
*Full contracts. Partly as a result of the verifiability goal, but also for clarity and documentation, the contracts associated with classes and features should describe the relevant semantics in its entirety.&lt;br /&gt;
&lt;br /&gt;
*Simple and consistent hierarchy, in particular avoidance of descendant hiding and of &amp;quot;taxomania&amp;quot; (classes not representing a meaningful abstraction, unnecessary inheritance links).&lt;br /&gt;
&lt;br /&gt;
*As in Classic EiffelBase, application of a systematic classification (a theory) of fundamental data structures.&lt;br /&gt;
&lt;br /&gt;
*Full traversal mechanisms, based on external cursors (with internal cursors also provided when useful).&lt;br /&gt;
&lt;br /&gt;
*Client-interface compatibility with corresponding classes in Classic EiffelBase, whenever it does not conflict with the preceding goals.&lt;br /&gt;
&lt;br /&gt;
==Design overview==&lt;br /&gt;
[[Image:eb2_container.png|left|Container class hierarchy]]&lt;br /&gt;
[[Image:eb2_iterator.png|left|Iterator class hierarchy]]&lt;br /&gt;
&lt;br /&gt;
==Model-based contracts==&lt;br /&gt;
&lt;br /&gt;
==Status and roadmap==&lt;br /&gt;
&lt;br /&gt;
Development of EiffelBase has started as a project at ETH Zurich; see the [http://eiffelbase2.origo.ethz.ch/ project page]. Documentation and other material will soon be transferred to the present page.&lt;/div&gt;</summary>
		<author><name>Kenga</name></author>	</entry>

	</feed>