From: Michel Quercia <michel.quercia@prepas.org>
To: doug@bagley.org (Doug Bagley)
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] some Hashtbl observations
Date: Mon, 4 Feb 2002 08:57:45 +0100 [thread overview]
Message-ID: <20020204085745.41c58120.michel.quercia@prepas.org> (raw)
In-Reply-To: <15453.36509.586757.825002@ns.bagley.org>
Le Sun, 3 Feb 2002 13:25:17 -0600
doug@bagley.org (Doug Bagley) écrivit :
> I recently had occasion to create a hash table to remember some Num's
> I was generating. Of course, I didn't figure out right away that you
> can't directly use the generic interface for Hashtbl with the type
> "Num".
> ...
> Exception: Failure "equal: abstract value".
I ran into this problem when developping the Bigint interface for Numerix.
You'll find in numerix-0.19
(http://pauillac.inria.fr/~quercia/cdrom/bibs/numerix-0.19a.tar.gz) a work
around implementing the missing functions (generic compare and generic
hash) for nats. Below is the patch file used in numerix-0.19 :
---------------------- cut here ----------------------------------
*** otherlibs/num/nat_stubs.c.orig Fri Aug 24 15:08:51 2001
--- otherlibs/num/nat_stubs.c Fri Aug 24 15:46:58 2001
***************
*** 11,16 ****
--- 11,18 ----
/***********************************************************************/
/* $Id: nat_stubs.c,v 1.10 2000/04/20 16:20:59 xleroy Exp $ */
+ /* Modified by M.Quercia on August 24th, 2001 for generic compare and
hash */+ /* All modified lines end with the comment MQ */
#define CAML_LIGHT
#include "alloc.h"
***************
*** 28,39 ****
static void serialize_nat(value, unsigned long *, unsigned long *);
static unsigned long deserialize_nat(void * dst);
static struct custom_operations nat_operations = {
"_nat",
custom_finalize_default,
! custom_compare_default,
! custom_hash_default,
serialize_nat,
deserialize_nat
};
--- 30,43 ----
static void serialize_nat(value, unsigned long *, unsigned long *);
static unsigned long deserialize_nat(void * dst);
+ static int nat_compare(value a, value b); /* MQ */
+ static long nat_hash(value a); /* MQ */
static struct custom_operations nat_operations = {
"_nat",
custom_finalize_default,
! nat_compare, /* custom_compare_default, MQ */
! nat_hash, /* custom_hash_default, MQ */
serialize_nat,
deserialize_nat
};
***************
*** 331,333 ****
--- 335,350 ----
return len * 4;
}
+ /* custom comparison MQ */
+ static int nat_compare(value a, value b) { /* MQ */
+ return (BnnCompare(Bignum_val(a), Wosize_val(a) - 1, /* MQ */
+ Bignum_val(b), Wosize_val(b) - 1)); /* MQ */
+ } /* MQ */
+
+ /* hashing, borrowed from ocaml/byterun/hash.c MQ */
+ static long nat_hash(value a) { /* MQ */
+ unsigned long l = Wosize_val(a) - 1, accu = l, i; /* MQ */
+ for (i=0; i<l; i++) /* MQ */
+ accu = accu*65599 + BnGetDigit(Bignum_val(a),i); /* MQ */
+ return(accu); /* MQ */
+ } /* MQ */
---------------------- cut here ----------------------------------
Refer to the Numerix doc (file doc/numerix-eng.ps, page 42) for
instructions.
Regards,
--
Michel Quercia
57 rue abbé Grégoire, 38000 Grenoble
http://michel.quercia.free.fr (maths)
http://pauillac.inria.fr/~quercia (informatique)
mailto:michel.quercia@prepas.org
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
next prev parent reply other threads:[~2002-02-04 7:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-02-03 19:25 Doug Bagley
2002-02-04 7:57 ` Michel Quercia [this message]
2002-02-04 8:52 ` Jean-Christophe Filliatre
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20020204085745.41c58120.michel.quercia@prepas.org \
--to=michel.quercia@prepas.org \
--cc=caml-list@inria.fr \
--cc=doug@bagley.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox