19 #define BITS_PER_PELEM (sizeof(PELEM)*8)
21 #if defined(DUMP_PART_INIT) || defined(UNIT_TESTS)
22 static const char *readable_cutmask(
PELEM mask) {
28 if (mask&1) readable[b] =
'1';
37 longs((((len + 7) / 8)+sizeof(
PELEM)-1) / sizeof(
PELEM)),
50 for (
int i=0; i<j; i++) {
59 #if defined(DUMP_PART_INIT)
60 printf(
"leafs=%i\n", len);
61 printf(
"cutmask='%s'\n", readable_cutmask(cutmask));
62 printf(
"longs=%i (can hold %zu bits)\n", longs, possible);
63 printf(
"bits=%i\n", bits);
68 #if defined(NTREE_DEBUG_FUNCTIONS)
73 void PART::stop_pretty_printing() { namesPtr =
NULp; }
83 for (
int part = 0; part<=1; ++part) {
85 for (
int i=0; i<longs; i++) {
87 for (
int j=0; k<plen &&
size_t(j)<
sizeof(
PELEM)*8; j++, k++) {
88 bool bitset = p[i] & el;
90 const char *name = names[k];
92 fputc(name[0], stdout);
94 if (!first)
fputc(
',', stdout);
103 fputs(
"---", stdout);
109 for (
int i=0; i<longs; i++) {
111 for (
int j=0; k<plen &&
size_t(j)<
sizeof(
PELEM)*8; j++, k++) {
112 bool bitset = p[i] & el;
113 fputc(
'0'+bitset, stdout);
119 printf(
" len=%.5f prob=%5.1f%% w.len=%.5f leaf=%i dist2center=%i\n",
143 for (
int i=0; i<longs; i++) {
144 if (p[i] & other->p[i])
return true;
158 for (
int i=0; i<longs; i++) {
173 for (
int i=0; i<longs; i++) {
174 p[i] = p[i] ^ superset->p[i];
193 for (
int i=0; i<longs; i++) {
194 p[i] |= source->p[i];
198 members += source->members;
201 members = count_members();
215 for (
int i=0; i<longs; i++) {
216 if (p[i] != other->p[i])
return false;
228 for (
int i=0; i<longs; i++) {
237 for (uint8_t b = 0; b<8; ++b) {
246 for (
unsigned i = 0; i<256; ++i) {
256 #if defined(DUMP_PART_DISTANCE)
257 fprintf(stdout,
"bitcount(%04x) = ", e);
259 for (
size_t bi = 0; bi<
sizeof(e); ++bi) {
263 #if defined(DUMP_PART_DISTANCE)
264 fprintf(stdout,
"%i\n", leafs);
269 int PART::count_members()
const {
273 for (
int i = 0; i<(longs-1); ++i) {
319 for (
int i=0; i<longs; i++) {
321 pos = i *
sizeof(
PELEM) * 8;
323 for (; p_temp; p_temp >>= 1, pos++) {
335 if (
this == other)
return 0;
345 cmp = centerdist1-centerdist2;
352 cmp =
id - other->id;
362 return p1<p2 ? -1 : (p1>p2 ? 1 : 0);
368 if (
this == other)
return 0;
373 int cmp = members - other->members;
376 for (
int i = 0; !cmp && i<longs; ++i) {
386 #if defined(DUMP_PART_DISTANCE)
387 static void dumpbits(
const PELEM p) {
390 bool bitset = p & el;
391 fputc(
"-1"[bitset], stdout);
415 #if defined(DUMP_PART_DISTANCE)
417 fputs(
"other: ", stdout); other->print();
418 fputs(
"this_superset: ", stdout); this_superset->print();
419 fputs(
"other_superset:", stdout); other_superset->print();
423 #if defined(ASSERTION_USED)
424 if (
this != this_superset) {
432 if (other != other_superset) {
445 for (
int i = 0; i<longs; ++i) {
446 PELEM ts = this_superset->p[i];
447 PELEM os = other_superset->p[i];
449 if (i == (longs-1)) {
456 const PELEM O = ts ^ os;
457 const PELEM si = ts & os;
459 const PELEM t0 = p[i] & si;
460 const PELEM o0 = other->p[i] & si;
462 const PELEM ti = t0 ^ si;
463 const PELEM oi = o0 ^ si;
466 const PELEM d00 = t0 ^ o0;
467 const PELEM d0i = t0 ^ oi;
468 const PELEM di0 = ti ^ o0;
469 const PELEM dii = ti ^ oi;
476 #if defined(DUMP_PART_DISTANCE)
478 #define DUMPBITS(var) do { fprintf(stdout, "%5s = %04x = ", #var, var); dumpbits(var); fputc('\n', stdout); } while(0)
479 #define DUMPINT(var) fprintf(stdout, "%5s = %i\n", #var, var)
503 #if defined(DUMP_PART_DISTANCE)
504 fprintf(stdout,
"resulting dist=%i\n", dist);
543 void TEST_PartRegistry() {
555 TEST_EXPECT_EQUAL(readable_cutmask(reg.get_cutmask()),
"00000000000000000000000000000001");
562 TEST_EXPECT_EQUAL(readable_cutmask(reg.get_cutmask()),
"01111111111111111111111111111111");
569 TEST_EXPECT_EQUAL(readable_cutmask(reg.get_cutmask()),
"11111111111111111111111111111111");
576 TEST_EXPECT_EQUAL(readable_cutmask(reg.get_cutmask()),
"00000000000000000000000000000001");
583 TEST_EXPECT_EQUAL(readable_cutmask(reg.get_cutmask()),
"01111111111111111111111111111111");
int topological_cmp(const PART *other) const
int PELEM_cmp(const PELEM &p1, const PELEM &p2)
const TreeNode * get_origin(const PART *part)
bool is_leaf_edge() const
int get_members(const PART *part)
void invertInSuperset(const PART *superset)
int calcDistance(const PART *e1, const PART *e2, const PART *t1, const PART *t2)
uint8_t bytebitcount(uint8_t byte)
bool is_standardized() const
PELEM get_cutmask() const
PART * create_root() const
bool bit_is_set(int pos) const
bool disjunct_from(const PART *other) const
bool equals(const PART *other) const
void add_members_from(const PART *source)
int distanceTo(const PART *other, const PART *this_superset, const PART *other_superset) const
fputs(TRACE_PREFIX, stderr)
str readable(const copy< T > &v)
int insertionOrder_cmp(const PART *other) const
bool is_real_son_of(const PART *father) const
const TreeNode * get_origin() const
bool is_subset_of(const PART *other) const
int distance_to_tree_center() const
bool overlaps_with(const PART *other) const
void destroy_part(PART *part)
#define TEST_EXPECT_EQUAL(expr, want)