-
Notifications
You must be signed in to change notification settings - Fork 0
/
lhs_value.c
41 lines (34 loc) · 897 Bytes
/
lhs_value.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "lhs_value.h"
const char* lhsvalue_typename[] =
{
"null", "integer", "number", "boolean", "delegate", "gc",
"vm", "frame", "string", "function","fulldata", "table"
};
long long lhsvalue_hashformula(const char* str, size_t l, size_t seed)
{
if (!seed)
{
seed = ((l << 2) + (l >> 1)) & 0xffff;
}
long long h = seed ^ l;
for (; l > 0; l--)
{
h ^= ((h << 5) + (h >> 2) + (char)(str[l - 1]));
}
return h;
}
long long lhsvalue_hashstr(void* data)
{
LHSString* str = lhsvalue_caststring(data);
return lhsvalue_hashformula(str->data, str->length, 0);
}
int lhsvalue_equalstr(void* data1, void* data2)
{
LHSString* s1 = lhsvalue_caststring(data1),
* s2 = lhsvalue_caststring(data2);
if (s1->length != s2->length)
{
return LHS_FALSE;
}
return !memcmp(s1->data, s2->data, s1->length);
}