This commit is contained in:
Dmitry Boulytchev 2020-09-01 17:23:36 +03:00
parent 81be668d4e
commit f16f695ed3
5 changed files with 31 additions and 4 deletions

Binary file not shown.

View file

@ -50,3 +50,4 @@ F,time;
F,kindOf;
F,compareTags;
F,flatCompare;
F,tagHash;

View file

@ -157,7 +157,7 @@ static void failure (char *s, ...) {
do if (!UNBOXED(x)) failure ("unboxed value expected in %s\n", memo); while (0)
# define ASSERT_STRING(memo, x) \
do if (!UNBOXED(x) && TAG(TO_DATA(x)->tag) \
!= STRING_TAG) failure ("sting value expected in %s\n", memo); while (0)
!= STRING_TAG) failure ("string value expected in %s\n", memo); while (0)
typedef struct {
int tag;
@ -334,11 +334,33 @@ extern int Blength (void *p) {
return BOX(LEN(a->tag));
}
static char* chars = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'";
extern int LtagHash (char *s) {
char *p;
int h = 0, limit = 0, pos = 0;
ASSERT_STRING("tagHash: 1", s);
p = s;
while (*p && limit++ < 4) {
char *q = chars;
for (; *q && *q != *p; q++, pos++);
if (*q) h = (h << 6) | pos;
else failure ("tagHash: character not found: %c\n", *p);
p++;
}
return BOX(h);
}
char* de_hash (int n) {
static char *chars = (char*) BOX (NULL);
// static char *chars = (char*) BOX (NULL);
static char buf[6] = {0,0,0,0,0,0};
char *p = (char *) BOX (NULL);
chars = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'";
p = &buf[5];
#ifdef DEBUG_PRINT

View file

@ -42,10 +42,14 @@ returns a string, acquired via processing these arguments according to the forma
\descr{\lstinline|fun hash (value)|}{Returns integer hash for the argument value; also works for cyclic data structures.}
\descr{\lstinline|fun tagHash (s)|}{Returns an integer value for a hash of tag, represented by string \lstinline|s|.}
\descr{\lstinline|fun compare (value1, value2)|}{Performs a structural deep comparison of two values. Determines a
linear order relation for every pairs of values. Returns \lstinline|0| if the values are structurally equal, negative or
positive integers otherwise. May not work for cyclic data structures.}
\descr{\lstinline|fun flatCompare (x, y)|}{Performs a shallow comparison of two values. The result is similar to that for \lstinline|compare|.}
\descr{\lstinline|fun fst (value)|}{Returns the first subvalue for a given boxed value.}
\descr{\lstinline|fun snd (value)|}{Returns the second subvalue for a given boxed value.}

View file

@ -1 +1 @@
let version = "Version 1.00, 6f72275cf, Thu Aug 27 07:24:46 2020 +0300"
let version = "Version 1.00, 81be668d4, Tue Sep 1 06:20:39 2020 +0300"