78 #include <config_auto.h>
81 #include "allheaders.h"
105 if (pnaindex) *pnaindex = NULL;
107 return (
PTA *)ERROR_PTR(
"ptas not defined", __func__, NULL);
109 return (
PTA *)ERROR_PTR(
"invalid sort type", __func__, NULL);
111 return (
PTA *)ERROR_PTR(
"invalid sort order", __func__, NULL);
114 return (
PTA *)ERROR_PTR(
"naindex not made", __func__, NULL);
122 return (
PTA *)ERROR_PTR(
"ptad not made", __func__, NULL);
147 return ERROR_INT(
"&naindex not defined", __func__, 1);
150 return ERROR_INT(
"ptas not defined", __func__, 1);
152 return ERROR_INT(
"invalid sort type", __func__, 1);
154 return ERROR_INT(
"invalid sort order", __func__, 1);
159 return ERROR_INT(
"na not made", __func__, 1);
160 for (i = 0; i < n; i++) {
172 return ERROR_INT(
"naindex not made", __func__, 1);
194 return (
PTA *)ERROR_PTR(
"ptas not defined", __func__, NULL);
196 return (
PTA *)ERROR_PTR(
"naindex not defined", __func__, NULL);
201 return (
PTA *)ERROR_PTR(
"ptad not made", __func__, NULL);
202 for (i = 0; i < n; i++) {
228 return (
PTAA *)ERROR_PTR(
"ptaas not defined", __func__, NULL);
230 return (
PTAA *)ERROR_PTR(
"naindex not defined", __func__, NULL);
234 return (
PTAA *)ERROR_PTR(
"numa and ptaa sizes differ", __func__, NULL);
236 for (i = 0; i < n; i++) {
267 return ERROR_INT(
"&val not defined", __func__, 1);
270 return ERROR_INT(
"pta not defined", __func__, 1);
272 return ERROR_INT(
"invalid sort type", __func__, 1);
273 if (fract < 0.0 || fract > 1.0)
274 return ERROR_INT(
"fract not in [0.0 ... 1.0]", __func__, 1);
276 return ERROR_INT(
"pta empty", __func__, 1);
283 index = (l_int32)(fract * (l_float32)(n - 1) + 0.5);
309 l_int32 index, i, j, n, nx, ny, start, end;
310 l_float32 x, y, yp, val;
311 NUMA *na1, *na2, *nas, *nax;
315 return (
PTA *)ERROR_PTR(
"pta not defined", __func__, NULL);
327 for (i = 1; i < n; i++) {
340 for (i = 0, index = 0; i < ny; i++) {
343 nx = end - start + 1;
350 for (j = 0; j < nx; j++) {
356 for (j = 0; j < nx; j++) {
392 l_float32 x1, y1, x2, y2;
396 return ERROR_INT(
"&same not defined", __func__, 1);
399 return ERROR_INT(
"pta1 and pta2 not both defined", __func__, 1);
403 if (n1 != n2)
return 0;
408 for (i = 0; i < n1; i++) {
411 if (x1 != x2 || y1 != y2) {
443 return (
L_ASET *)ERROR_PTR(
"pta not defined", __func__, NULL);
445 set = l_asetCreate(L_UINT_TYPE);
447 for (i = 0; i < n; i++) {
451 l_asetInsert(set, key);
483 return ERROR_INT(
"&ptad not defined", __func__, 1);
486 return ERROR_INT(
"ptas not defined", __func__, 1);
488 set = l_asetCreate(L_UINT_TYPE);
492 for (i = 0; i < n; i++) {
496 if (!l_asetFind(set, key)) {
498 l_asetInsert(set, key);
534 return ERROR_INT(
"&ptad not defined", __func__, 1);
537 return ERROR_INT(
"pta1 not defined", __func__, 1);
539 return ERROR_INT(
"pta2 not defined", __func__, 1);
574 l_int32 n1, n2, i, n, x, y;
578 PTA *pta_small, *pta_big, *ptad;
581 return ERROR_INT(
"&ptad not defined", __func__, 1);
584 return ERROR_INT(
"pta1 not defined", __func__, 1);
586 return ERROR_INT(
"pta2 not defined", __func__, 1);
591 pta_small = (n1 < n2) ? pta1 : pta2;
592 pta_big = (n1 < n2) ? pta2 : pta1;
599 set2 = l_asetCreate(L_UINT_TYPE);
600 for (i = 0; i < n; i++) {
604 if (l_asetFind(set1, key) && !l_asetFind(set2, key)) {
606 l_asetInsert(set2, key);
610 l_asetDestroy(&set1);
611 l_asetDestroy(&set2);
640 return (
L_HASHMAP *)ERROR_PTR(
"pta not defined", __func__, NULL);
643 if ((hmap = l_hmapCreate(0.51 * n, 2)) == NULL)
644 return (
L_HASHMAP *)ERROR_PTR(
"hmap not made", __func__, NULL);
645 for (i = 0; i < n; i++) {
648 hitem = l_hmapLookup(hmap, key, i, L_HMAP_CREATE);
672 l_int32 i, x, y, tabsize;
677 if (phmap) *phmap = NULL;
679 return ERROR_INT(
"&ptad not defined", __func__, 1);
682 return ERROR_INT(
"ptas not defined", __func__, 1);
686 return ERROR_INT(
"hmap not made", __func__, 1);
690 for (i = 0; i < tabsize; i++) {
702 l_hmapDestroy(&hmap);
728 return ERROR_INT(
"&ptad not defined", __func__, 1);
731 return ERROR_INT(
"pta1 not defined", __func__, 1);
733 return ERROR_INT(
"pta2 not defined", __func__, 1);
736 if (
ptaJoin(pta3, pta2, 0, -1) == 1) {
738 return ERROR_INT(
"pta join failed", __func__, 1);
764 l_int32 i, n1, n2, n, x, y;
766 PTA *pta_small, *pta_big, *ptad;
771 return ERROR_INT(
"&ptad not defined", __func__, 1);
774 return ERROR_INT(
"pta1 not defined", __func__, 1);
776 return ERROR_INT(
"pta2 not defined", __func__, 1);
781 pta_small = (n1 < n2) ? pta1 : pta2;
782 pta_big = (n1 < n2) ? pta2 : pta1;
784 return ERROR_INT(
"hmap not made", __func__, 1);
794 for (i = 0; i < n; i++) {
797 hitem = l_hmapLookup(hmap, key, i, L_HMAP_CHECK);
798 if (!hitem || hitem->
count == 0)
803 l_hmapDestroy(&hmap);
l_ok numaAddNumber(NUMA *na, l_float32 val)
numaAddNumber()
l_ok numaGetFValue(NUMA *na, l_int32 index, l_float32 *pval)
numaGetFValue()
NUMA * numaCreate(l_int32 n)
numaCreate()
void numaDestroy(NUMA **pna)
numaDestroy()
l_int32 numaGetCount(NUMA *na)
numaGetCount()
l_ok numaGetIValue(NUMA *na, l_int32 index, l_int32 *pival)
numaGetIValue()
NUMA * numaSort(NUMA *naout, NUMA *nain, l_int32 sortorder)
numaSort()
NUMA * numaGetSortIndex(NUMA *na, l_int32 sortorder)
numaGetSortIndex()
PTAA * ptaaCreate(l_int32 n)
ptaaCreate()
PTA * ptaaGetPta(PTAA *ptaa, l_int32 index, l_int32 accessflag)
ptaaGetPta()
l_ok ptaGetIPt(PTA *pta, l_int32 index, l_int32 *px, l_int32 *py)
ptaGetIPt()
l_ok ptaaAddPta(PTAA *ptaa, PTA *pta, l_int32 copyflag)
ptaaAddPta()
l_int32 ptaaGetCount(PTAA *ptaa)
ptaaGetCount()
l_ok ptaAddPt(PTA *pta, l_float32 x, l_float32 y)
ptaAddPt()
l_ok ptaGetPt(PTA *pta, l_int32 index, l_float32 *px, l_float32 *py)
ptaGetPt()
l_int32 ptaGetCount(PTA *pta)
ptaGetCount()
PTA * ptaCreate(l_int32 n)
ptaCreate()
void ptaDestroy(PTA **ppta)
ptaDestroy()
PTA * ptaCopy(PTA *pta)
ptaCopy()
l_ok ptaJoin(PTA *ptad, PTA *ptas, l_int32 istart, l_int32 iend)
ptaJoin()
PTA * ptaSort(PTA *ptas, l_int32 sorttype, l_int32 sortorder, NUMA **pnaindex)
ptaSort()
l_ok ptaUnionByHmap(PTA *pta1, PTA *pta2, PTA **pptad)
ptaUnionByHmap()
PTA * ptaSort2d(PTA *pta)
ptaSort2d()
L_ASET * l_asetCreateFromPta(PTA *pta)
l_asetCreateFromPta()
l_ok ptaIntersectionByAset(PTA *pta1, PTA *pta2, PTA **pptad)
ptaIntersectionByAset()
l_ok ptaUnionByAset(PTA *pta1, PTA *pta2, PTA **pptad)
ptaUnionByAset()
PTAA * ptaaSortByIndex(PTAA *ptaas, NUMA *naindex)
ptaaSortByIndex()
l_ok ptaEqual(PTA *pta1, PTA *pta2, l_int32 *psame)
ptaEqual()
l_ok ptaGetRankValue(PTA *pta, l_float32 fract, PTA *ptasort, l_int32 sorttype, l_float32 *pval)
ptaGetRankValue()
l_ok ptaRemoveDupsByAset(PTA *ptas, PTA **pptad)
ptaRemoveDupsByAset()
l_ok ptaIntersectionByHmap(PTA *pta1, PTA *pta2, PTA **pptad)
ptaIntersectionByHmap()
l_ok ptaRemoveDupsByHmap(PTA *ptas, PTA **pptad, L_HASHMAP **phmap)
ptaRemoveDupsByHmap()
L_HASHMAP * l_hmapCreateFromPta(PTA *pta)
l_hmapCreateFromPta()
l_ok ptaGetSortIndex(PTA *ptas, l_int32 sorttype, l_int32 sortorder, NUMA **pnaindex)
ptaGetSortIndex()
PTA * ptaSortByIndex(PTA *ptas, NUMA *naindex)
ptaSortByIndex()
struct L_Hashitem ** hashtab
l_ok l_hashPtToUint64(l_int32 x, l_int32 y, l_uint64 *phash)
l_hashPtToUint64()