Esempio n. 1
0
static int query(Node *x, const Space &sp) {
    if (!x)
        return 0;
    if (x->space.in(sp))
        return x->sum;
    if (x->space.out(sp))
        return 0;

    return query(x->NE, sp) + query(x->NW, sp) + query(x->SE, sp) +
           query(x->SW, sp) + (sp.contain(*x->point) ? x->value : 0);
}
Esempio n. 2
0
static int query(Node *x, const Space &sp) {
    if (!x) {
        return 0;
    }

    // printf("Querying (%d, %d)...\n", x->point->x, x->point->y);

    if (x->space.out(sp)) {
        puts("Out");
        return 0;
    } else if (x->space.in(sp)) {
        puts("In");
        return x->size;
    } else {
        return query(x->NE, sp) + query(x->NW, sp) + query(x->SE, sp) +
               query(x->SW, sp) + (sp.contain(*(x->point)) ? 1 : 0);
    }
}
Esempio n. 3
0
  Family operator()( int color, const Space& sub )
  {
    Space base, margin;
    Family adjs;

    for ( typename Space::const_iterator it = base_.begin()
        ; it != base_.end(); ++it
        )
    {
      typename Space::const_point pt( it );

      if ( color_[ pt.index ] == color ) base.join( pt.element );
    }
    for ( typename Space::const_iterator it = base.begin()
        ; it != base.end(); ++it
        )
    {
      typename Space::const_point pt0( it );
#ifdef ELAI_USE_C11
      const Space&& adj = std::move( adjacent_( pt0.element ) );
#else
      const Space adj = adjacent_( pt0.element );
#endif
      Neighbour neigh( Element( pt0.element, color ) );

      for ( typename Space::const_iterator jt = adj.begin()
          ; jt != adj.end(); ++jt
          )
      {
        typename Space::const_point pt( jt );
        const Element pt1( pt.element, color );

        if ( !base.contain( pt.element ) && !margin.contain( pt.element ) )
          margin.join( pt.element, Element( pt.element, color ) ); // ( BASE, RECOLORED )
        if ( !sub.contain( pt1 ) ) continue;
        neigh.join( pt1 );
      }
      adjs.join( neigh );
    }
    for ( typename Space::const_marginal_iterator it = margin.internal_begin()
        ; it != margin.internal_end(); ++it
        )
    {
      typename Space::const_internal_point pt0( it );
#ifdef ELAI_USE_C11
      const Space&& adj = std::move( adjacent_( pt0.element ) );
#else
      const Space adj = adjacent_( pt0.internal ); // BASE ELEMENT
#endif
      Neighbour neigh( pt0.external ); // RECOLORED ELEMENT

      for ( typename Space::const_iterator jt = adj.begin(); jt != adj.end(); ++jt )
      {
        typename Space::const_point pt( jt );
        const Element pt1( pt.element, color );

        if ( !sub.contain( pt1 ) ) continue;
        neigh.join( pt1 );
      }
      adjs.join( neigh );
    }

    return adjs;
  }