Re: is_equal of HASHABLE

Frank Boehme <[email protected]>
Newsgroups gmane.comp.lang.eiffel.smalleiffel
Message-ID <[email protected]>
Dominique Colnet wrote:

> Philippe Ribet has pointed out a possible drawback of your
> proposal: we now have two concrete bodies (one inherited from
> ANY and one in HASHABLE).
> Knowing that HASHABLE is very often used together with multiple
> inheritance... it may bothering for people to undefine the good
> one in order to select the best body.
> So, the idea I have is to propose to redefine is_equal as
> deferred :-)
> 
> Here is the new proposal to be discussed / tested:
> 
> ----------------------------------------
> deferred class HASHABLE
> insert ANY
>       redefine is_equal
>       end
> feature {ANY}
> 
>       is_equal(other: like Current): BOOLEAN is
>           deferred
>           ensure then
>             Result implies hash_code = other.hash_code
>           end
>   ...

Yes, to me that looks more suitable for general purpose programs, i.e.
where it is the intention just to make objects hashable.
BTW, in my G2F3 code a more special situation arises since hundreds of
thousands of game positions may be stored in the transposition table.
Obviuously, I am concerned about memory usage which is why I store only
that part of information which determines whether two positions are
identical or different and who is to move next. This is what the feature
{STORAGE_HASHABLE}.hash_key: HASH_KEY does. Now, in that (admittedly
special) case, HASH_KEY key inherits only from HASHABLE and its
attributes are only expanded types so that the built-in definition of
is_equal will always do. But I agree that Dominque's suggestion (defer
is_equal in HASHABLE and adding the psotcondition) is a good decision:
It guarantees that the assumptions which are made in HASHED_SET and
HASHED_DICTIONARY are checked by a contract and it does not impose much
hassle.

cheers,

Frank


-- 
Dr Frank Boehme                      | Email: [email protected]
National University of Ireland, Cork | phone: +353-21-4903163
Dept of Computer Science             |   fax: +353-21-4903113
Cork, Ireland                        |

Did you know that if you play a Windows XP cd backwards, you
will hear the voice of Satan?
That's nothing! If you play it forward, it'll install Windows XP.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.