8000 Store original moc order · postgrespro/pgsphere@3c51f93 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3c51f93

Browse files
df7cbmsdemlei
authored andcommitted
Store original moc order
1 parent 27708bd commit 3c51f93

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

expected/moc.out

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ SELECT '(0.78, 0.81)'::spoint <@ '7/123-456,1000-2000'::smoc;
5757
SELECT '0/'::smoc = '1/'::smoc AS eq;
5858
eq
5959
----
60-
t
60+
f
6161
(1 row)
6262

6363
SELECT '0/1,3,7'::smoc = '0/1,3,7' AS eq;
@@ -347,7 +347,7 @@ SELECT max_order(smoc(''));
347347
SELECT max_order(smoc('1/'));
348348
max_order
349349
-----------
350-
0
350+
1
351351
(1 row)
352352

353353
SELECT max_order(smoc('1/1'));
@@ -364,7 +364,7 @@ HINT: The first value of a range (here 10) must be less than the second one (he
364364
SELECT max_order(smoc('1/0-3'));
365365
max_order
366366
-----------
367-
0
367+
1
368368
(1 row)
369369

370370
SELECT max_order(smoc('1/0-1'));
@@ -382,19 +382,19 @@ SELECT max_order(smoc('29/0-1'));
382382
SELECT max_order(smoc('29/0-3'));
383383
max_order
384384
-----------
385-
28
385+
29
386386
(1 row)
387387

388388
SELECT max_order(smoc('29/0-7'));
389389
max_order
390390
-----------
391-
28
391+
29
392392
(1 row)
393393

394394
SELECT max_order(smoc('29/0-15'));
395395
max_order
396396
-----------
397-
27
397+
29
398398
(1 row)
399399

400400
select set_smoc_output_type(0);

moc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ smoc_in(PG_FUNCTION_ARGS)
155155
}
156156
order = nb;
157157
npix = c_npix(order);
158+
moc_in_context_set_order(moc_in_context, order);
158159
}
159160
else if (c == ',') /* nb is a Healpix index */
160161
{
@@ -970,7 +971,7 @@ smoc_spoint(PG_FUNCTION_ARGS)
970971
last = c_healpix_convert_nest(pixel + 1, order, HEALPIX_MAX_ORDER);
971972

972973
moc_in_context = create_moc_in_context(moc_error_out);
973-
moc_healpix(moc_in_context, first, last, moc_error_out);
974+
moc_healpix(moc_in_context, order, first, last, moc_error_out);
974975

975976
moc_size = VARHDRSZ + get_moc_size(moc_in_context, moc_error_out);
976977
moc_ret = (Smoc*) palloc0(moc_size);

pgs_process_moc.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ release_moc_in_context(void*, pgs_error_handler);
9797
void
9898
add_to_moc(void*, long, hpint64, hpint64, pgs_error_handler);
9999

100+
void
101+
moc_in_context_set_order(void* moc_in_context, int order);
102+
100103
int
101104
get_moc_size(void*, pgs_error_handler);
102105

@@ -151,7 +154,7 @@ moc_round(void* moc_in_context, int order, Smoc* moc_a, int32 moc_a_end,
151154
pgs_error_handler error_out);
152155

153156
void
154-
moc_healpix(void* moc_in_context, hpint64 first, hpint64 last,
157+
moc_healpix(void* moc_in_context, int order, hpint64 first, hpint64 last,
155158
pgs_error_handler error_out);
156159

157160
void

process_moc.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ struct moc_input
273273
size_t options_bytes;
274274
size_t options_size;
275275
layout_vec layout;
276+
int order = 0;
276277

277278
std::string s;
278279
moc_input() : options_bytes(0), options_size(0)
@@ -440,6 +441,15 @@ add_to_moc(void* moc_in_context, long order, hpint64 first, hpint64 last,
440441
PGS_CATCH
441442
};
442443

444+
void
445+
moc_in_context_set_order(void* moc_in_context, int order)
446+
{
447+
moc_input* p = static_cast<moc_input*>(moc_in_context);
448+
moc_input & m = *p;
449+
if (order > m.order)
450+
m.order = order;
451+
}
452+
443453
// get_moc_size() prepares creation of MOC
444454

445455
static
@@ -643,12 +653,15 @@ create_moc_release_context(void* moc_in_context, Smoc* moc,
643653

644654
moc->tree_begin = tree_begin; // start of level-end section
645655
moc->area = area;
656+
/*
646657
// simple linear search shift loop to calculate the moc order
647658
int order;
648659
for (order = 29; order > 0; --order, order_log >>= 2)
649660
if (order_log & 3)
650661
break;
651662
moc->order = order;
663+
*/
664+
moc->order = m.order; // moc order provided by caller
652665
moc->first = 0; // first Healpix index in set
653666
moc->last = 0; // 1 + (last Healpix index in set)
654667
if (m.input_map.size())
@@ -872,6 +885,8 @@ moc_union(void* moc_in_context, Smoc* moc_a, int32 moc_a_end, Smoc* moc_b, int32
872885
moc_interval & x = *interval_ptr(moc_b, j);
873886
add_to_map(m.input_map, x.first, x.second);
874887
}
888+
889+
m.order = std::max(moc_a->order, moc_b->order);
875890
PGS_CATCH
876891
};
877892

@@ -918,6 +933,8 @@ moc_intersection(void* moc_in_context, Smoc* moc_a, int32 moc_a_end, Smoc* moc_b
918933
else
919934
b += entry_size;
920935
}
936+
937+
m.order = std::max(moc_a->order, moc_b->order);
921938
PGS_CATCH
922939
}
923940

@@ -944,18 +961,21 @@ moc_round(void* moc_in_context, int order, Smoc* moc_a, int32 moc_a_end,
944961

945962
add_to_map(m.input_map, first, second);
946963
}
964+
965+
m.order = order;
947966
PGS_CATCH
948967
}
949968

950969
void
951-
moc_healpix(void* moc_in_context, hpint64 first, hpint64 last,
970+
moc_healpix(void* moc_in_context, int order, hpint64 first, hpint64 last,
952971
pgs_error_handler error_out)
953972
{
954973
moc_input* p = static_cast<moc_input*>(moc_in_context);
955974
moc_input & m = *p;
956975
PGS_TRY
957976
moc_map_entry input(first, last);
958977
m.input_map.insert(m.input_map.end(), input);
978+
m.order = order;
959979
PGS_CATCH
960980
}
961981

@@ -982,6 +1002,7 @@ moc_disc(void* moc_in_context, int order, double theta, double phi, double radiu
9821002
m.input_map.insert(m.input_map.end(), input);
9831003
}
9841004

1005+
m.order = order;
9851006
PGS_CATCH
9861007
}
9871008

@@ -1015,5 +1036,6 @@ moc_polygon(void* moc_in_context, int order, int32 npts, float8 *polygon,
10151036
m.input_map.insert(m.input_map.end(), input);
10161037
}
10171038

1039+
m.order = order;
10181040
PGS_CATCH
10191041
}

0 commit comments

Comments
 (0)
0