version 1.12, 2012/08/01 00:37:08
|
version 1.13, 2012/08/29 13:51:30
|
Line 653 io_findKeyVars(array_t * __restrict vars, u_short key)
|
Line 653 io_findKeyVars(array_t * __restrict vars, u_short key)
|
io_arrayDestroy(&tmp); |
io_arrayDestroy(&tmp); |
return v; |
return v; |
} |
} |
|
|
|
/* |
|
* io_hashVar() - Generate hash key for variable from string or value |
|
* |
|
* @v = variable |
|
* @key = key string for hash, if =NULL hash will built from variable |
|
* return: hash key |
|
*/ |
|
u_short |
|
io_hashVar(ait_val_t * __restrict v, const char * __restrict key) |
|
{ |
|
void *p; |
|
u_short cksum; |
|
int l; |
|
|
|
if (!v) |
|
return 0; |
|
|
|
if (key) { |
|
p = (void*) key; |
|
l = (strlen(key) + 1) / 2; |
|
} else { |
|
switch (AIT_TYPE(v)) { |
|
case empty: |
|
AIT_KEY(v) = 0; |
|
return 0; |
|
case string: |
|
case buffer: |
|
p = AIT_ADDR(v); |
|
l = AIT_LEN(v) / 2; |
|
break; |
|
case data: |
|
p = v->val_data; |
|
l = AIT_LEN(v) / 2; |
|
break; |
|
default: |
|
p = &AIT_RAW(v); |
|
l = sizeof AIT_RAW(v) / 2; |
|
break; |
|
} |
|
} |
|
|
|
cksum = crcFletcher16((u_short*) p, l); |
|
|
|
if (AIT_BE(v)) |
|
AIT_KEY(v) = htobe16(cksum); |
|
else if (AIT_LE(v)) |
|
AIT_KEY(v) = htole16(cksum); |
|
else |
|
AIT_KEY(v) = cksum; |
|
|
|
return AIT_KEY(v); |
|
} |
|
|
|
/* |
|
* io_hashKeyVars() - Generate hash keys for variables |
|
* |
|
* @vars = Variables |
|
* return -1 error or 0 ok |
|
*/ |
|
inline int |
|
io_hashKeyVars(array_t * __restrict vars) |
|
{ |
|
register int i; |
|
|
|
if (!vars) |
|
return -1; |
|
|
|
for (i = 0; i < io_arraySize(vars); i++) |
|
io_hashVar(io_array(vars, i, ait_val_t*), NULL); |
|
|
|
return 0; |
|
} |
|
|
|
/* |
|
* io_findKeyHash() - Find variable by hash string from array |
|
* |
|
* @vars = Variables |
|
* @key = Search string |
|
* return: NULL error or not found, !=NULL valid element |
|
*/ |
|
inline ait_val_t * |
|
io_findKeyHash(array_t * __restrict vars, const char * __restrict key) |
|
{ |
|
u_short k = 0; |
|
|
|
if (!vars || !key) |
|
return NULL; |
|
|
|
k = crcFletcher16((u_short*) key, (strlen(key) + 1) / 2); |
|
return io_findKeyVars(vars, k); |
|
} |
|
|