h_map.sa


Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
 
------------------------->  GNU Sather - sourcefile  <-------------------------
-- Copyright (C) 2000 by K Hopper, University of Waikato, New Zealand        --
-- This file is part of the GNU Sather library. It is free software; you may --
-- redistribute  and/or modify it under the terms of the GNU Library General --
-- Public  License (LGPL)  as published  by the  Free  Software  Foundation; --
-- either version 2 of the license, or (at your option) any later version.   --
-- This  library  is distributed  in the  hope that it will  be  useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/LGPL for more details.       --
-- The license text is also available from:  Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                     --
-------------->  Please email comments to <bug-sather@gnu.org>  <--------------


class H_MAP_IMPL{K,ELT}

class H_MAP_IMPL{K,ELT} is -- This class is an implementation of a map based on a hash table. -- Version 1.2 Nov 98. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 9 Apr 96 bv Original -- 3 Apr 97 kh Changed for CARD instead of INT -- 9 Nov 98 kh Revised for 1.2, added pre/post conditions private include DYNAMIC_DATABUCKET_TABLE{K,ELT} create -> create, map_has_ind -> has_ind, map_copy -> copy, map_pair! -> elt!, map_key! -> ind!, map_delete -> map_delete, map_aget -> aget, map_aset -> aset ; size : CARD is -- This routine merely renames n_inds. return n_inds end ; insert( elem : TUP{K,ELT} ) : SAME pre ~void(self) and ~void(elem) post result.has_ind(elem.t1) is -- This routine returns a new copy of self with the addition of -- the given element. res : SAME := copy ; res.aset(elem.t1,elem.t2) ; return res end ; delete( key : K ) pre ~void(self) post ~has_ind(key) is -- This version of delete does not return the key element. dummy : ELT := map_delete(key) end ; delete( elem : TUP{K,ELT} ) pre ~void(self) post ~contains(elem) is -- This routine deletes the pair by deleting the entry associated with -- the key in the pair. delete(elem.t1) end ; target! : ELT pre ~void(self) post true -- (result = aget(ind!)) is -- This iter is a synonym for elt! loop index : K := ind! ; yield aget(index) end end ; end ; -- H_MAP_IMPL{K,ELT}

class VMAP{ITP,TTP} < $VMAP{ITP,TTP}

class VMAP{ITP,TTP} < $VMAP{ITP,TTP} is -- This class provides an implementation of maps using a hash table -- based on data buckets. -- Version 1.1 Nov 98. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 9 Apr 96 bv Original for 1.2 -- 9 Nov 98 kh Revised, added pre/post conditions include MAP_INCL{ITP,TTP} size -> ; include H_MAP_IMPL{ITP,TTP} delete -> private delete, aset -> private aset ; is_eq( anything : $OB ) : BOOL is -- This predicate returns true if and only if self an anything have -- the same value. typecase anything when $RO_BAG{TUP{ITP,TTP}} then if size /= anything.size then return false end ; loop elem : TUP{ITP,TTP} := anything.unique! ; if count(elem) /= anything.count(elem) then return false end end ; return true else return false end end ; hash : CARD pre true -- irrespective of value post true -- irrespective of result is -- This routine produces a hash function based upon all of the elements -- of the map. res : NUM_BITS := NUM_BITS::create ; loop elem : TUP{ITP,TTP} := elt! ; if res.card = 0 then res := NUM_BITS::create(elt_hash(elem)) else res := res.convolve(NUM_BITS::create(elt_hash(elem))) end end ; return res.card end ; end ; -- VMAP{ITP,TTP}

class MAP{ITP,TTP} < $MAP{ITP,TTP}

class MAP{ITP,TTP} < $MAP{ITP,TTP} is -- This class is an implementation of the map abstraction using -- a hash table. -- Version 1.1 Nov 98. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 9 Apr 97 bv Original for 1.2 -- 9 Nov 98 kh Revised, added pre/post conditions include MAP_INCL{ITP,TTP} size -> ; include H_MAP_IMPL{ITP,TTP} ; end ; -- MAP{ITP,TTP}