mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-06 06:48:48 +00:00
tagHash
This commit is contained in:
parent
81be668d4e
commit
f16f695ed3
5 changed files with 31 additions and 4 deletions
BIN
lama-spec.pdf
BIN
lama-spec.pdf
Binary file not shown.
|
|
@ -50,3 +50,4 @@ F,time;
|
|||
F,kindOf;
|
||||
F,compareTags;
|
||||
F,flatCompare;
|
||||
F,tagHash;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue