summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--byterun/hash.c15
-rw-r--r--byterun/mlvalues.h3
2 files changed, 18 insertions, 0 deletions
diff --git a/byterun/hash.c b/byterun/hash.c
index af756eaf2..114d9d69c 100644
--- a/byterun/hash.c
+++ b/byterun/hash.c
@@ -131,3 +131,18 @@ static void hash_aux(value obj)
a priori unknown structure. Use its physical address as hash key. */
Combine((long) obj);
}
+
+/* Hashing variant tags */
+
+value hash_variant(char * tag)
+{
+ value accu;
+ /* Same hashing algorithm as in ../typing/btype.ml, function hash_variant */
+ for (accu = Val_int(0); *tag != 0; tag++)
+ accu = Val_int(223 * Int_val(accu) + *((unsigned char *) tag));
+ accu = accu & Val_int((1 << 31) - 1);
+ /* Force sign extension of bit 31 for compatibility between 32 and 64-bit
+ platforms */
+ return (int32) accu;
+}
+
diff --git a/byterun/mlvalues.h b/byterun/mlvalues.h
index cfa06d26d..434adba94 100644
--- a/byterun/mlvalues.h
+++ b/byterun/mlvalues.h
@@ -176,6 +176,9 @@ typedef opcode_t * code_t;
#define Class_val(val) Field(val, 0)
#define Oid_val(val) Long_val(Field(val, 1))
+/* Another special case: variants */
+extern value hash_variant(char * tag);
+
/* 2- If tag >= No_scan_tag : a sequence of bytes. */
/* Pointer to the first byte */