MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / paint

Function paint

internal/cbm/pdf/pdf_font.c:393–454  ·  view source on GitHub ↗

Disjoint segments, ascending, each owned by the winning interval. The list * is consumed (sorted). Intervals must have hi < UINT64_MAX. */

Source from the content-addressed store, hash-verified

391/* Disjoint segments, ascending, each owned by the winning interval. The list
392 * is consumed (sorted). Intervals must have hi < UINT64_MAX. */
393static pdf_seg_t *paint(pdf_doc_t *d, iv_list_t *l, bool first_wins, int *nout) {
394 *nout = 0;
395 if (!l->n) {
396 return NULL;
397 }
398 int n = l->n;
399 qsort(l->v, (size_t)n, sizeof(*l->v), iv_lo_cmp);
400 uint64_t *pts = (uint64_t *)cbm_alloc(CBM_MEM_CLASS_EXTRACT, (size_t)n * 2 * sizeof(uint64_t));
401 int *heap = (int *)cbm_alloc(CBM_MEM_CLASS_EXTRACT, (size_t)n * sizeof(int));
402 pdf_seg_t *seg = (pdf_seg_t *)pdf_big(d, (size_t)n * 2 * sizeof(pdf_seg_t));
403 if (!pts || !heap || !seg) {
404 cbm_free(CBM_MEM_CLASS_EXTRACT, pts);
405 cbm_free(CBM_MEM_CLASS_EXTRACT, heap);
406 d->nomem = true;
407 return NULL;
408 }
409 int np = 0;
410 for (int i = 0; i < n; i++) {
411 pts[np++] = l->v[i].lo;
412 pts[np++] = l->v[i].hi + 1;
413 }
414 qsort(pts, (size_t)np, sizeof(uint64_t), u64_cmp);
415 iv_heap_t hp = {heap, 0, l->v, first_wins};
416 int next = 0;
417 int ns = 0;
418 for (int k = 0; k < np; k++) {
419 if (k > 0 && pts[k] == pts[k - 1]) {
420 continue;
421 }
422 uint64_t x = pts[k];
423 while (next < n && l->v[next].lo <= x) {
424 heap_push(&hp, next++);
425 }
426 while (hp.n && l->v[hp.h[0]].hi < x) {
427 heap_pop(&hp);
428 }
429 if (!hp.n) {
430 continue;
431 }
432 int k2 = k + 1;
433 while (k2 < np && pts[k2] == x) {
434 k2++;
435 }
436 if (k2 >= np) {
437 break;
438 }
439 uint64_t end = pts[k2] - 1;
440 int w = l->v[hp.h[0]].idx;
441 if (ns && seg[ns - 1].idx == w && seg[ns - 1].hi + 1 == x) {
442 seg[ns - 1].hi = end;
443 } else {
444 seg[ns].lo = x;
445 seg[ns].hi = end;
446 seg[ns].idx = w;
447 ns++;
448 }
449 }
450 cbm_free(CBM_MEM_CLASS_EXTRACT, pts);

Callers 2

cmap_parseFunction · 0.70
font_init_type0Function · 0.70

Calls 5

cbm_allocFunction · 0.85
pdf_bigFunction · 0.85
cbm_freeFunction · 0.85
heap_pushFunction · 0.85
heap_popFunction · 0.85

Tested by

no test coverage detected