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);
120 numaDestroy(&naindex);
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);
157 n = ptaGetCount(ptas);
158 if ((na = numaCreate(n)) == NULL)
159 return ERROR_INT(
"na not made", __func__, 1);
160 for (i = 0; i < n; i++) {
161 ptaGetPt(ptas, i, &x, &y);
163 numaAddNumber(na, x);
165 numaAddNumber(na, y);
169 nai = numaGetSortIndex(na, sortorder);
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);
199 n = numaGetCount(naindex);
200 if ((ptad = ptaCreate(n)) == NULL)
201 return (
PTA *)ERROR_PTR(
"ptad not made", __func__, NULL);
202 for (i = 0; i < n; i++) {
203 numaGetIValue(naindex, i, &index);
204 ptaGetPt(ptas, index, &x, &y);
205 ptaAddPt(ptad, x, y);
228 return (
PTAA *)ERROR_PTR(
"ptaas not defined", __func__, NULL);
230 return (
PTAA *)ERROR_PTR(
"naindex not defined", __func__, NULL);
232 n = ptaaGetCount(ptaas);
233 if (numaGetCount(naindex) != n)
234 return (
PTAA *)ERROR_PTR(
"numa and ptaa sizes differ", __func__, NULL);
235 ptaad = ptaaCreate(n);
236 for (i = 0; i < n; i++) {
237 numaGetIValue(naindex, i, &index);
238 pta = ptaaGetPta(ptaas, index,
L_COPY);
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);
275 if ((n = ptaGetCount(pta)) == 0)
276 return ERROR_INT(
"pta empty", __func__, 1);
283 index = (l_int32)(fract * (l_float32)(n - 1) + 0.5);
285 ptaGetPt(ptas, index, pval, NULL);
287 ptaGetPt(ptas, index, NULL, pval);
289 if (!ptasort) ptaDestroy(&ptas);
309l_int32 index, i, j, n, nx, ny, start, end;
310l_float32 x, y, yp, val;
311NUMA *na1, *na2, *nas, *nax;
315 return (
PTA *)ERROR_PTR(
"pta not defined", __func__, NULL);
322 n = ptaGetCount(pta1);
325 numaAddNumber(na1, 0);
326 ptaGetPt(pta1, 0, &x, &yp);
327 for (i = 1; i < n; i++) {
328 ptaGetPt(pta1, i, &x, &y);
330 numaAddNumber(na1, i);
331 numaAddNumber(na2, i - 1);
335 numaAddNumber(na2, n - 1);
339 ny = numaGetCount(na1);
340 for (i = 0, index = 0; i < ny; i++) {
341 numaGetIValue(na1, i, &start);
342 numaGetIValue(na2, i, &end);
343 nx = end - start + 1;
345 ptaGetPt(pta1, index++, &x, &y);
346 ptaAddPt(ptad, x, y);
349 nax = numaCreate(nx);
350 for (j = 0; j < nx; j++) {
351 ptaGetPt(pta1, index + j, &x, &y);
352 numaAddNumber(nax, x);
356 for (j = 0; j < nx; j++) {
357 numaGetFValue(nas, j, &val);
358 ptaAddPt(ptad, val, y);
392l_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);
401 n1 = ptaGetCount(pta1);
402 n2 = ptaGetCount(pta2);
403 if (n1 != n2)
return 0;
408 for (i = 0; i < n1; i++) {
409 ptaGetPt(ptas1, i, &x1, &y1);
410 ptaGetPt(ptas2, i, &x2, &y2);
411 if (x1 != x2 || y1 != y2) {
443 return (
L_ASET *)ERROR_PTR(
"pta not defined", __func__, NULL);
445 set = l_asetCreate(L_UINT_TYPE);
446 n = ptaGetCount(pta);
447 for (i = 0; i < n; i++) {
448 ptaGetIPt(pta, i, &x, &y);
449 l_hashPtToUint64(x, y, &hash);
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);
489 n = ptaGetCount(ptas);
492 for (i = 0; i < n; i++) {
493 ptaGetIPt(ptas, i, &x, &y);
494 l_hashPtToUint64(x, y, &hash);
496 if (!l_asetFind(set, key)) {
497 ptaAddPt(ptad, x, y);
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);
542 pta3 = ptaCopy(pta1);
543 ptaJoin(pta3, pta2, 0, -1);
574l_int32 n1, n2, i, n, x, y;
578PTA *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);
589 n1 = ptaGetCount(pta1);
590 n2 = ptaGetCount(pta2);
591 pta_small = (n1 < n2) ? pta1 : pta2;
592 pta_big = (n1 < n2) ? pta2 : pta1;
598 n = ptaGetCount(pta_small);
599 set2 = l_asetCreate(L_UINT_TYPE);
600 for (i = 0; i < n; i++) {
601 ptaGetIPt(pta_small, i, &x, &y);
602 l_hashPtToUint64(x, y, &hash);
604 if (l_asetFind(set1, key) && !l_asetFind(set2, key)) {
605 ptaAddPt(ptad, x, y);
606 l_asetInsert(set2, key);
610 l_asetDestroy(&set1);
611 l_asetDestroy(&set2);
639 return (
L_HASHMAP *)ERROR_PTR(
"pta not defined", __func__, NULL);
641 n = ptaGetCount(pta);
642 if ((hmap = l_hmapCreate(0.51 * n, 2)) == NULL)
643 return (
L_HASHMAP *)ERROR_PTR(
"hmap not made", __func__, NULL);
644 for (i = 0; i < n; i++) {
645 ptaGetIPt(pta, i, &x, &y);
646 l_hashPtToUint64(x, y, &key);
647 l_hmapLookup(hmap, key, i, L_HMAP_CREATE);
671l_int32 i, x, y, tabsize;
676 if (phmap) *phmap = NULL;
678 return ERROR_INT(
"&ptad not defined", __func__, 1);
681 return ERROR_INT(
"ptas not defined", __func__, 1);
685 return ERROR_INT(
"hmap not made", __func__, 1);
689 for (i = 0; i < tabsize; i++) {
692 ptaGetIPt(ptas, hitem->
val, &x, &y);
693 ptaAddPt(ptad, x, y);
701 l_hmapDestroy(&hmap);
727 return ERROR_INT(
"&ptad not defined", __func__, 1);
730 return ERROR_INT(
"pta1 not defined", __func__, 1);
732 return ERROR_INT(
"pta2 not defined", __func__, 1);
734 pta3 = ptaCopy(pta1);
735 if (ptaJoin(pta3, pta2, 0, -1) == 1) {
737 return ERROR_INT(
"pta join failed", __func__, 1);
763l_int32 i, n1, n2, n, x, y;
765PTA *pta_small, *pta_big, *ptad;
770 return ERROR_INT(
"&ptad not defined", __func__, 1);
773 return ERROR_INT(
"pta1 not defined", __func__, 1);
775 return ERROR_INT(
"pta2 not defined", __func__, 1);
778 n1 = ptaGetCount(pta1);
779 n2 = ptaGetCount(pta2);
780 pta_small = (n1 < n2) ? pta1 : pta2;
781 pta_big = (n1 < n2) ? pta2 : pta1;
783 return ERROR_INT(
"hmap not made", __func__, 1);
792 n = ptaGetCount(pta_small);
793 for (i = 0; i < n; i++) {
794 ptaGetIPt(pta_small, i, &x, &y);
795 l_hashPtToUint64(x, y, &key);
796 hitem = l_hmapLookup(hmap, key, i, L_HMAP_CHECK);
797 if (!hitem || hitem->
count == 0)
799 ptaAddPt(ptad, x, y);
802 l_hmapDestroy(&hmap);
l_ok ptaUnionByHmap(PTA *pta1, PTA *pta2, PTA **pptad)
ptaUnionByHmap()
PTA * ptaSort(PTA *ptas, l_int32 sorttype, l_int32 sortorder, NUMA **pnaindex)
ptaSort()
l_ok ptaIntersectionByAset(PTA *pta1, PTA *pta2, PTA **pptad)
ptaIntersectionByAset()
L_ASET * l_asetCreateFromPta(PTA *pta)
l_asetCreateFromPta()
l_ok ptaUnionByAset(PTA *pta1, PTA *pta2, PTA **pptad)
ptaUnionByAset()
PTA * ptaSort2d(PTA *pta)
ptaSort2d()
PTA * ptaSortByIndex(PTA *ptas, NUMA *naindex)
ptaSortByIndex()
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_HASHMAP * l_hmapCreateFromPta(PTA *pta)
l_hmapCreateFromPta()
PTAA * ptaaSortByIndex(PTAA *ptaas, NUMA *naindex)
ptaaSortByIndex()
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_ok ptaGetSortIndex(PTA *ptas, l_int32 sorttype, l_int32 sortorder, NUMA **pnaindex)
ptaGetSortIndex()
struct L_Hashitem ** hashtab