Re: Alternative generic hash function

From: Pierre Weis (Pierre.Weis@inria.fr)
Date: Thu May 25 2000 - 09:00:43 MET DST

  • Next message: STARYNKEVITCH Basile: "Alternative generic hash function"

    > The generic hash function Hashtbl.hash traverses into mutable data
    > structures. So I get different hash values depending on updates of the data
    > structure.
    [...]
    > As was pointed out times before on this list, Hashtbl.hash is thus
    > unsuitable for hashing on data structures that contain mutable data.
    >
    > I'm wondering what the design rational is for this choice. I'd rather have a
    > generic hash function (Hashtbl.hash_pure) that never looks into mutable
    > structures (skips refs and mutable fields of records and classes).
    [...]

    The rationale is simple: there is no way to distinguish between
    mutable and immutable data structures at runtime. So, there is no
    possibility to implement the suggested hash_pure function in a
    polymorphic way. If you really want to use keys that belong to a
    mutable data structure (which is not a good idea anyway), you should
    use the functorial interface to hash tables to specify your own
    hashing function, that would implement hash_pure on your particular
    key type.

    Best regards,

    -- 
    Pierre Weis
    

    INRIA, Projet Cristal, http://pauillac.inria.fr/~weis



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