74 #include "allheaders.h" 101 l_int32 n, i, j, gap;
103 PROCNAME(
"sarraySort");
106 return (
SARRAY *)ERROR_PTR(
"sain not defined", procName, NULL);
111 else if (sain != saout)
112 return (
SARRAY *)ERROR_PTR(
"invalid: not in-place", procName, NULL);
113 array = saout->
array;
117 for (gap = n/2; gap > 0; gap = gap / 2) {
118 for (i = gap; i < n; i++) {
119 for (j = i - gap; j >= 0; j -= gap) {
126 array[j] = array[j + gap];
127 array[j + gap] = tmp;
152 PROCNAME(
"sarraySortByIndex");
155 return (
SARRAY *)ERROR_PTR(
"sain not defined", procName, NULL);
157 return (
SARRAY *)ERROR_PTR(
"naindex not defined", procName, NULL);
161 for (i = 0; i < n; i++) {
188 l_int32 i, len1, len2, len;
190 PROCNAME(
"sarrayCompareLexical");
193 return ERROR_INT(
"str1 not defined", procName, 1);
195 return ERROR_INT(
"str2 not defined", procName, 1);
199 len = L_MIN(len1, len2);
201 for (i = 0; i < len; i++) {
202 if (str1[i] == str2[i])
204 if (str1[i] > str2[i])
242 PROCNAME(
"sarrayUnionByAset");
245 return (
SARRAY *)ERROR_PTR(
"sa1 not defined", procName, NULL);
247 return (
SARRAY *)ERROR_PTR(
"sa2 not defined", procName, NULL);
286 PROCNAME(
"sarrayRemoveDupsByAset");
289 return (
SARRAY *)ERROR_PTR(
"sas not defined", procName, NULL);
291 set = l_asetCreate(L_UINT_TYPE);
294 for (i = 0; i < n; i++) {
298 if (!l_asetFind(
set, key)) {
300 l_asetInsert(
set, key);
332 l_int32 n1, n2, i, n;
336 SARRAY *sa_small, *sa_big, *sad;
338 PROCNAME(
"sarrayIntersectionByAset");
341 return (
SARRAY *)ERROR_PTR(
"sa1 not defined", procName, NULL);
343 return (
SARRAY *)ERROR_PTR(
"sa2 not defined", procName, NULL);
348 sa_small = (n1 < n2) ? sa1 : sa2;
349 sa_big = (n1 < n2) ? sa2 : sa1;
355 set2 = l_asetCreate(L_UINT_TYPE);
356 for (i = 0; i < n; i++) {
360 if (l_asetFind(set1, key) && !l_asetFind(set2, key)) {
362 l_asetInsert(set2, key);
366 l_asetDestroy(&set1);
367 l_asetDestroy(&set2);
387 PROCNAME(
"l_asetCreateFromSarray");
390 return (
L_ASET *)ERROR_PTR(
"sa not defined", procName, NULL);
392 set = l_asetCreate(L_UINT_TYPE);
394 for (i = 0; i < n; i++) {
398 l_asetInsert(
set, key);
436 l_int32 i, n, index, items;
442 PROCNAME(
"sarrayRemoveDupsByHash");
444 if (pdahash) *pdahash = NULL;
446 return ERROR_INT(
"&sad not defined", procName, 1);
449 return ERROR_INT(
"sas not defined", procName, 1);
456 for (i = 0, items = 0; i < n; i++) {
492 l_int32 n1, n2, nsmall, i, index1, index2;
496 SARRAY *sa_small, *sa_big, *sad;
498 PROCNAME(
"sarrayIntersectionByHash");
501 return (
SARRAY *)ERROR_PTR(
"sa1 not defined", procName, NULL);
503 return (
SARRAY *)ERROR_PTR(
"sa2 not defined", procName, NULL);
508 sa_small = (n1 < n2) ? sa1 : sa2;
509 sa_big = (n1 < n2) ? sa2 : sa1;
519 for (i = 0; i < nsmall; i++) {
569 l_int32 i, nvals, index;
573 PROCNAME(
"sarrayFindStringByHash");
576 return ERROR_INT(
"&index not defined", procName, 1);
579 return ERROR_INT(
"sa not defined", procName, 1);
581 return ERROR_INT(
"dahash not defined", procName, 1);
589 for (i = 0; i < nvals; i++) {
592 if (!strcmp(str, stri)) {
628 for (i = 0; i < n; i++) {
654 PROCNAME(
"sarrayGenerateIntegers");
657 return (
SARRAY *)ERROR_PTR(
"sa not made", procName, NULL);
658 for (i = 0; i < n; i++) {
659 snprintf(buf,
sizeof(buf),
"%d", i);
689 const char *keystring,
692 char *key, *val, *str;
696 PROCNAME(
"sarrayLookupCSKV");
699 return ERROR_INT(
"&valstring not defined", procName, 1);
702 return ERROR_INT(
"sa not defined", procName, 1);
704 return ERROR_INT(
"keystring not defined", procName, 1);
707 for (i = 0; i < n; i++) {
710 sarraySplitString(sa1, str,
",");
717 if (!strcmp(key, keystring)) {
L_DNA * l_dnaHashGetDna(L_DNAHASH *dahash, l_uint64 key, l_int32 copyflag)
l_dnaHashGetDna()
l_int32 l_dnaGetCount(L_DNA *da)
l_dnaGetCount()
SARRAY * sarrayCopy(SARRAY *sa)
sarrayCopy()
SARRAY * sarrayGenerateIntegers(l_int32 n)
sarrayGenerateIntegers()
void l_dnaHashDestroy(L_DNAHASH **pdahash)
l_dnaHashDestroy()
char * stringNew(const char *src)
stringNew()
SARRAY * sarrayUnionByAset(SARRAY *sa1, SARRAY *sa2)
sarrayUnionByAset()
l_ok l_dnaGetIValue(L_DNA *da, l_int32 index, l_int32 *pival)
l_dnaGetIValue()
SARRAY * sarrayCreate(l_int32 n)
sarrayCreate()
L_ASET * l_asetCreateFromSarray(SARRAY *sa)
l_asetCreateFromSarray()
l_ok findNextLargerPrime(l_int32 start, l_uint32 *pprime)
findNextLargerPrime()
L_DNAHASH * l_dnaHashCreateFromSarray(SARRAY *sa)
l_dnaHashCreateFromSarray()
SARRAY * sarrayRemoveDupsByAset(SARRAY *sas)
sarrayRemoveDupsByAset()
l_ok l_dnaHashAdd(L_DNAHASH *dahash, l_uint64 key, l_float64 value)
l_dnaHashAdd()
l_ok numaGetIValue(NUMA *na, l_int32 index, l_int32 *pival)
numaGetIValue()
SARRAY * sarraySortByIndex(SARRAY *sain, NUMA *naindex)
sarraySortByIndex()
l_ok sarrayAddString(SARRAY *sa, const char *string, l_int32 copyflag)
sarrayAddString()
l_int32 stringCompareLexical(const char *str1, const char *str2)
stringCompareLexical()
l_ok l_hashStringToUint64(const char *str, l_uint64 *phash)
l_hashStringToUint64()
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
l_ok sarrayRemoveDupsByHash(SARRAY *sas, SARRAY **psad, L_DNAHASH **pdahash)
sarrayRemoveDupsByHash()
l_int32 sarrayGetCount(SARRAY *sa)
sarrayGetCount()
l_ok sarrayLookupCSKV(SARRAY *sa, const char *keystring, char **pvalstring)
sarrayLookupCSKV()
l_ok sarrayJoin(SARRAY *sa1, SARRAY *sa2)
sarrayJoin()
SARRAY * sarraySort(SARRAY *saout, SARRAY *sain, l_int32 sortorder)
sarraySort()
l_ok sarrayFindStringByHash(SARRAY *sa, L_DNAHASH *dahash, const char *str, l_int32 *pindex)
sarrayFindStringByHash()
SARRAY * sarrayIntersectionByAset(SARRAY *sa1, SARRAY *sa2)
sarrayIntersectionByAset()
L_DNAHASH * l_dnaHashCreate(l_int32 nbuckets, l_int32 initsize)
l_dnaHashCreate()
SARRAY * sarrayIntersectionByHash(SARRAY *sa1, SARRAY *sa2)
sarrayIntersectionByHash()
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()