inline UL& get_rev_diag( UL x ) { if( x <size_max()/2 ) { PUL ind = tri_ind(x , size_x() , size_y() ); return get_x_y( ind.first , size_y() - ind.second - 1 ); } else { UL xm = size_max() - x -1; PUL ind = tri_ind(xm , size_x() , size_y() ); return get_x_y( size_x() - ind.first - 1 , ind.second ); } }
inline UL& get_spiral( UL x ) { UL all = 0; UL be = 0; if( x > size_max() ) std::cout << "INFINITE LOOP WARNING" << std::endl; while( true ) { UL db = ( all%2 ? size_x() : size_y() ) - 1 - be*2; //std::cout << x << " " << db << std::endl; if( x < db ) { switch( all ) { case 0 : return (*this)[be][be + x]; case 1 : return (*this)[be+x][size_y()-be-1]; case 2 : return (*this)[size_x()-be-1][size_y()-be-1-x]; case 3 : return (*this)[size_x()-be-1-x][be]; } } else { x-=db; if(++all == 4) { all = 0; ++be; } } } }
inline UL& get_double_spiral_transposed( UL x ) { if( size_x() != size_y() ) std::cout << "WARNING!!" << std::endl; UL all = 0; UL be = 0; if( size_max() % 2 ) { if( size_max()/2 == x ) return get_x_y( size_x()/2 , size_y()/2 ); } bool v = x < size_max()/2; if( !v ) x = size_max() - x - 1; PUL p; while( true ) { UL db = ( all%2 ? size_x() : size_y() ) - 1 - be*2 + !!be; if( x <= db ) { switch( all ) { case 0 : p = PUL{be,(be? be-1:0) + x}; break; case 1 : p = PUL{be-1+x,size_y()-be}; break; case 2 : p = PUL{size_x()-be-1,size_y()-be-x}; break; case 3 : p = PUL{size_x()-be-x,be-1}; break; } break; } else { x-=db; if(++all == 4) { all = 0; } if( all%2 ) { ++be; } } } if( v ) return get_x_y(p.second , p.first); else return get_x_y( size_y() - 1 - p.second , size_x() - 1 - p.first ); }
iterator end() { size_type i = nodes_.size() - 1; for (; i != size_max() && !nodes_used_[i]; --i); return iterator(this, i + 1); }
void clear() { nodes_.clear(); nodes_used_.clear(); deleted_items_ = 0; head_ = size_max(); }
iterator& operator--() { --pos_; while (pos_ != size_max() && !container_->nodes_used_[pos_]) --pos_; return *this; }
/* Allocate enough space in the provided buffer to fit the requested length in * after the write pointer. */ static ubik_error _buf_realloc(struct _ubik_buf *buf, size_t req_len) { size_t n; uint8_t *old_start; old_start = buf->start; n = buf->end - buf->start; n = size_max(n * n, n + req_len); ubik_realloc((void **) &buf->start, n, 1, buf->region); buf->read = buf->start + (buf->read - old_start); buf->write = buf->start + (buf->write - old_start); buf->end = buf->start + n; return OK; }
size_type insert(const T& item) { if (size_max() == head_) { const size_type new_index = nodes_.size(); nodes_.emplace_back(item); nodes_used_.push_back(true); return new_index; } else { const size_type new_index = head_; head_ = nodes_[head_].next; nodes_[new_index] = item_node_(item); nodes_used_[new_index] = true; --deleted_items_; return new_index; } }