Alternative generic hash function

From: STARYNKEVITCH Basile (Basile.Starynkevitch@cea.fr)
Date: Thu May 25 2000 - 09:14:37 MET DST

  • Next message: Dmitri Lomov: "Re: Alternative generic hash function"

    >>>>> "Manuel" == Manuel Fahndrich <maf@microsoft.com> writes:

        Manuel> The generic hash function Hashtbl.hash traverses into
        Manuel> mutable data structures. [...]

        Manuel> As was pointed out times before on this list, Hashtbl.hash
        Manuel> is thus unsuitable for hashing on data structures that
        Manuel> contain mutable data.

        Manuel> I'm wondering what the design rational is for this
        Manuel> choice. I'd rather have a generic hash function
        Manuel> (Hashtbl.hash_pure) that never looks into mutable
        Manuel> structures (skips refs and mutable fields of records and
        Manuel> classes).

    I disagree. And it is probably difficult to implement in current Ocaml
    (which lacks any reflective facilities). The runtime does not know
    about mutable fields! If I want to hash mutable data structure, I will
    provide a specific hashing function.

    What I am lacking of is an hashing function accepting parametric
    type. I would like to define

    type 'a symbol_t = { sym_name: string; sym_hash: int; sym_val: 'a option}

    Then have

    let make_symbol s = { sym_name= s; sym_hash= Hashtbl.hash s; sym_val= None}

    let hash_symbol { sym_hash= h } = h

    Unfortunately I cannot make an hashtable using hash_symbol as hashing
    function

    Actually, hashing is a difficult subject. Perhaps there should be
    several hashing modules in Ocaml stdlib?

    Regards

    N.B. Any opinions expressed here are only mine, and not of my organization.
    N.B. Les opinions exprimees ici me sont personnelles et n engagent pas le CEA.

    ---------------------------------------------------------------------
    Basile STARYNKEVITCH ---- Commissariat à l Energie Atomique
    DTA/LETI/DEIN/SLA * CEA/Saclay b.528 (p111f) * 91191 GIF/YVETTE CEDEX * France
    phone: 1,69.08.60.55; fax: 1.69.08.83.95 home: 1,46.65.45.53
    email: Basile point Starynkevitch at cea point fr



    This archive was generated by hypermail 2b29 : Thu May 25 2000 - 09:37:26 MET DST