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
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue