59 template <
class T1,
class T2>
62 new ((
void *) p) T1(
val);
88 template <
class T,
class tree_node_allocator = std::allocator<tree_node_<T> > >
107 #ifdef __SGI_STL_PORT
108 class iterator_base :
public stlport::bidirectional_iterator<T, ptrdiff_t> {
124 T* operator->()
const;
128 void skip_children();
129 unsigned int number_of_children()
const;
192 void set_first_parent_();
193 void find_leftmost_parent_();
228 template<
typename iter> iter parent(iter)
const;
234 template<
typename iter> iter erase(iter);
239 template<
typename iter> iter append_child(iter position);
240 template<
typename iter> iter append_child(iter position,
const T& x);
242 template<
typename iter> iter append_child(iter position, iter other_position);
248 template<
typename iter> iter insert(iter position,
const T& x);
253 template<
typename iter> iter insert_subtree(iter position,
const iterator_base& subtree);
255 template<
typename iter> iter insert_after(iter position,
const T& x);
258 template<
typename iter> iter replace(iter position,
const T& x);
260 template<
typename iter> iter replace(iter position,
const iterator_base& from);
266 template<
typename iter> iter
flatten(iter position);
270 template<
typename iter> iter reparent(iter position, iter from);
274 template<
typename iter> iter move_before(iter target, iter
source);
279 bool duplicate_leaves=
false);
282 template<
class StrictWeakOrdering>
285 template<
typename iter>
286 bool equal(
const iter& one,
const iter& two,
const iter& three)
const;
287 template<
typename iter,
class BinaryPredicate>
288 bool equal(
const iter& one,
const iter& two,
const iter& three, BinaryPredicate)
const;
289 template<
typename iter>
290 bool equal_subtree(
const iter& one,
const iter& two)
const;
291 template<
typename iter,
class BinaryPredicate>
292 bool equal_subtree(
const iter& one,
const iter& two, BinaryPredicate)
const;
344 iterator attachNode, oldParent, z, zz;
346 int nTopLevelNodes = number_of_siblings(begin());
349 newTree = subtree(newRoot, next_sibling(newRoot));
351 oldParent = parent(newRoot);
356 z = parent(oldParent);
357 attachNode =
newTree.reparent(attachNode, oldParent, next_sibling(oldParent));
365 if (nTopLevelNodes > 1) {
366 if (nTopLevelNodes > 2) {
370 while (z.
is_valid() && z != end()) {
371 zz = next_sibling(z);
372 newTree.reparent(attachNode, z, zz);
380 nChildren =
newTree.number_of_children(attachNode);
381 if (nChildren <= 1) {
382 oldParent =
newTree.parent(attachNode);
383 if (nChildren == 1) {
384 z =
newTree.reparent(oldParent, attachNode.
begin(), next_sibling(attachNode.
begin()));
395 void head_initialise_();
397 template<
class StrictWeakOrdering>
424 template <
class T,
class tree_node_allocator>
429 if(one.
node > two.
node)
return true;
437 template <
class T,
class tree_node_allocator>
443 template <
class T,
class tree_node_allocator>
450 template <
class T,
class tree_node_allocator>
455 replace(begin(), other);
458 template <
class T,
class tree_node_allocator>
462 alloc_.deallocate(
head,1);
463 alloc_.deallocate(feet,1);
466 template <
class T,
class tree_node_allocator>
475 head->prev_sibling=0;
476 head->next_sibling=feet;
481 feet->prev_sibling=
head;
482 feet->next_sibling=0;
485 template <
class T,
class tree_node_allocator>
491 template <
class T,
class tree_node_allocator>
498 template <
class T,
class tree_node_allocator>
503 while(it!=other.
end()) {
504 to=insert(to, (*it));
510 while(it!=other.
end()) {
519 template <
class T,
class tree_node_allocator>
523 while(
head->next_sibling!=feet)
527 template<
class T,
class tree_node_allocator>
538 alloc_.deallocate(
prev,1);
544 template<
class T,
class tree_node_allocator>
568 alloc_.deallocate(cur,1);
572 template <
class T,
class tree_node_allocator>
578 template <
class T,
class tree_node_allocator>
584 template <
class T,
class tree_node_allocator>
589 while(
tmp->first_child)
595 template <
class T,
class tree_node_allocator>
601 template <
class T,
class tree_node_allocator>
605 unsigned int curdepth=0;
607 while(
tmp->first_child==0) {
610 throw std::range_error(
"tree: begin_fixed out of range");
618 template <
class T,
class tree_node_allocator>
623 unsigned int curdepth=1;
625 while(
tmp->first_child==0) {
628 throw std::range_error(
"tree: end_fixed out of range");
636 template <
class T,
class tree_node_allocator>
645 template <
class T,
class tree_node_allocator>
653 template <
class T,
class tree_node_allocator>
654 template <
typename iter>
658 return iter(position.node->parent);
661 template <
class T,
class tree_node_allocator>
668 template <
class T,
class tree_node_allocator>
678 template <
class T,
class tree_node_allocator>
679 template <
typename iter>
689 tmp->parent=position.node;
690 if(position.node->last_child!=0) {
691 position.node->last_child->next_sibling=
tmp;
694 position.node->first_child=
tmp;
696 tmp->prev_sibling=position.node->last_child;
697 position.node->last_child=
tmp;
702 template <
class T,
class tree_node_allocator>
703 template <
class iter>
717 tmp->parent=position.node;
718 if(position.node->last_child!=0) {
719 position.node->last_child->next_sibling=
tmp;
722 position.node->first_child=
tmp;
724 tmp->prev_sibling=position.node->last_child;
725 position.node->last_child=
tmp;
730 template <
class T,
class tree_node_allocator>
731 template <
class iter>
737 return replace(aargh, other);
740 template <
class T,
class tree_node_allocator>
741 template <
class iter>
747 insert_subtree(position.end(), from);
753 template <
class T,
class tree_node_allocator>
760 template <
class T,
class tree_node_allocator>
761 template <
class iter>
764 if(position.node==0) {
773 tmp->parent=position.node->parent;
774 tmp->next_sibling=position.node;
775 tmp->prev_sibling=position.node->prev_sibling;
776 position.node->prev_sibling=
tmp;
778 if(
tmp->prev_sibling==0)
779 tmp->parent->first_child=
tmp;
781 tmp->prev_sibling->next_sibling=
tmp;
785 template <
class T,
class tree_node_allocator>
793 tmp->next_sibling=position.
node;
794 if(position.
node==0) {
797 tmp->parent->last_child=
tmp;
805 if(
tmp->prev_sibling==0)
806 tmp->parent->first_child=
tmp;
808 tmp->prev_sibling->next_sibling=
tmp;
812 template <
class T,
class tree_node_allocator>
813 template <
class iter>
821 tmp->parent=position.node->parent;
822 tmp->prev_sibling=position.node;
823 tmp->next_sibling=position.node->next_sibling;
824 position.node->next_sibling=
tmp;
826 if(
tmp->next_sibling==0) {
828 tmp->parent->last_child=
tmp;
831 tmp->next_sibling->prev_sibling=
tmp;
836 template <
class T,
class tree_node_allocator>
837 template <
class iter>
843 return replace(it, subtree);
856 template <
class T,
class tree_node_allocator>
857 template <
class iter>
865 template <
class T,
class tree_node_allocator>
866 template <
class iter>
875 erase_children(position);
896 alloc_.deallocate(current_to,1);
908 toit=append_child(toit, current_from->
data);
911 while(current_from->
next_sibling==0 && current_from!=start_from) {
912 current_from=current_from->
parent;
917 if(current_from!=
last) {
918 toit=append_child(parent(toit), current_from->
data);
921 }
while(current_from!=
last);
926 template <
class T,
class tree_node_allocator>
936 while((++orig_begin)!=orig_end)
939 while((++new_begin)!=new_end)
951 if(new_first==new_last)
971 template <
class T,
class tree_node_allocator>
972 template <
typename iter>
975 if(position.node->first_child==0)
980 tmp->parent=position.node->parent;
983 if(position.node->next_sibling) {
984 position.node->last_child->next_sibling=position.node->next_sibling;
985 position.node->next_sibling->prev_sibling=position.node->last_child;
988 position.node->parent->last_child=position.node->last_child;
990 position.node->next_sibling=position.node->first_child;
991 position.node->next_sibling->prev_sibling=position.node;
992 position.node->first_child=0;
993 position.node->last_child=0;
999 template <
class T,
class tree_node_allocator>
1000 template <
typename iter>
1005 if(begin==end)
return begin;
1007 while((++begin)!=end) {
1011 if(
first->prev_sibling==0) {
1012 first->parent->first_child=
last->next_sibling;
1015 first->prev_sibling->next_sibling=
last->next_sibling;
1017 if(
last->next_sibling==0) {
1018 last->parent->last_child=
first->prev_sibling;
1021 last->next_sibling->prev_sibling=
first->prev_sibling;
1023 if(position.node->first_child==0) {
1024 position.node->first_child=
first;
1025 position.node->last_child=
last;
1026 first->prev_sibling=0;
1029 position.node->last_child->next_sibling=
first;
1030 first->prev_sibling=position.node->last_child;
1031 position.node->last_child=
last;
1033 last->next_sibling=0;
1037 pos->
parent=position.node;
1038 if(pos==
last)
break;
1045 template <
class T,
class tree_node_allocator>
1048 if(from.node->first_child==0)
return position;
1049 return reparent(position, from.node->first_child, end(from));
1052 template <
class T,
class tree_node_allocator>
1060 if(dst==src)
return source;
1070 else dst->
parent->first_child=src;
1078 template <
class T,
class tree_node_allocator>
1081 bool duplicate_leaves)
1084 while(from1!=from2) {
1085 if((fnd=std::find(to1, to2, (*from1))) != to2) {
1087 if(duplicate_leaves)
1088 append_child(parent(to1), (*from1));
1091 merge(fnd.
begin(), fnd.
end(), from1.
begin(), from1.
end(), duplicate_leaves);
1095 insert_subtree(to2, from1);
1101 template <
class T,
class tree_node_allocator>
1102 template <
class StrictWeakOrdering>
1106 static StrictWeakOrdering comp;
1108 return comp(
a->data,
b->data);
1111 template <
class T,
class tree_node_allocator>
1115 sort(from, to, comp, deep);
1118 template <
class T,
class tree_node_allocator>
1119 template <
class StrictWeakOrdering>
1121 StrictWeakOrdering comp,
bool deep)
1123 if(from==to)
return;
1127 std::multiset<tree_node *, compare_nodes<StrictWeakOrdering> > nodes;
1130 nodes.insert(it.
node);
1139 typename std::multiset<tree_node *, compare_nodes<StrictWeakOrdering> >
::iterator nit=nodes.
begin(), eit=nodes.
end();
1141 if((*nit)->parent!=0)
1142 (*nit)->parent->first_child=(*nit);
1144 else prev->next_sibling=(*nit);
1148 (*nit)->prev_sibling=
prev;
1150 prev->next_sibling=(*nit);
1156 prev->next_sibling=(*eit);
1159 (*eit)->next_sibling=
next;
1160 (*eit)->prev_sibling=
prev;
1162 if((*eit)->parent!=0)
1163 (*eit)->parent->last_child=(*eit);
1165 else next->prev_sibling=(*eit);
1172 sort(begin(bcs), end(bcs), comp, deep);
1178 template <
class T,
class tree_node_allocator>
1179 template <
typename iter>
1182 std::equal_to<T> comp;
1183 return equal(one_, two, three_, comp);
1186 template <
class T,
class tree_node_allocator>
1187 template <
typename iter>
1190 std::equal_to<T> comp;
1191 return equal_subtree(one_, two_, comp);
1194 template <
class T,
class tree_node_allocator>
1195 template <
typename iter,
class BinaryPredicate>
1202 while(one!=two &&
is_valid(three)) {
1203 if(!fun(*one,*three))
1213 template <
class T,
class tree_node_allocator>
1214 template <
typename iter,
class BinaryPredicate>
1219 if(!fun(*one,*two))
return false;
1220 if(number_of_children(one)!=number_of_children(two))
return false;
1221 return equal(begin(one),end(one),begin(two),fun);
1224 template <
class T,
class tree_node_allocator>
1229 tmp.replace(
tmp.begin(),
tmp.end(), from, to);
1233 template <
class T,
class tree_node_allocator>
1237 tmp.replace(
tmp.begin(),
tmp.end(), from, to);
1240 template <
class T,
class tree_node_allocator>
1252 template <
class T,
class tree_node_allocator>
1259 template <
class T,
class tree_node_allocator>
1272 template <
class T,
class tree_node_allocator>
1276 if(pos==0)
return 0;
1288 template <
class T,
class tree_node_allocator>
1300 template <
class T,
class tree_node_allocator>
1335 template <
class T,
class tree_node_allocator>
1342 if(
tmp==it)
return true;
1348 template <
class T,
class tree_node_allocator>
1351 if(it.
node==0 || it.
node==feet)
return false;
1355 template <
class T,
class tree_node_allocator>
1375 template <
class T,
class tree_node_allocator>
1391 template <
class T,
class tree_node_allocator>
1393 : node(0), skip_current_children_(
false)
1397 template <
class T,
class tree_node_allocator>
1399 : node(tn), skip_current_children_(
false)
1403 template <
class T,
class tree_node_allocator>
1409 template <
class T,
class tree_node_allocator>
1412 return &(node->data);
1415 template <
class T,
class tree_node_allocator>
1418 if(other.
node!=this->node)
return true;
1422 template <
class T,
class tree_node_allocator>
1425 if(other.
node==this->node)
return true;
1429 template <
class T,
class tree_node_allocator>
1437 template <
class T,
class tree_node_allocator>
1445 template <
class T,
class tree_node_allocator>
1448 skip_current_children_=
true;
1451 template <
class T,
class tree_node_allocator>
1455 if(pos==0)
return 0;
1469 template <
class T,
class tree_node_allocator>
1475 template <
class T,
class tree_node_allocator>
1481 template <
class T,
class tree_node_allocator>
1487 template <
class T,
class tree_node_allocator>
1501 template <
class T,
class tree_node_allocator>
1505 if(!this->skip_current_children_ && this->node->first_child != 0) {
1506 this->node=this->node->first_child;
1509 this->skip_current_children_=
false;
1510 while(this->node->next_sibling==0) {
1511 this->node=this->node->parent;
1515 this->node=this->node->next_sibling;
1520 template <
class T,
class tree_node_allocator>
1524 if(this->node->prev_sibling) {
1525 this->node=this->node->prev_sibling;
1526 while(this->node->last_child)
1527 this->node=this->node->last_child;
1530 this->node=this->node->parent;
1537 template <
class T,
class tree_node_allocator>
1545 template <
class T,
class tree_node_allocator>
1553 template <
class T,
class tree_node_allocator>
1563 template <
class T,
class tree_node_allocator>
1577 template <
class T,
class tree_node_allocator>
1583 template <
class T,
class tree_node_allocator>
1589 template <
class T,
class tree_node_allocator>
1595 template <
class T,
class tree_node_allocator>
1609 template <
class T,
class tree_node_allocator>
1613 if(this->node->next_sibling==0)
1614 this->node=this->node->parent;
1616 this->node=this->node->next_sibling;
1617 if(this->skip_current_children_) {
1618 this->skip_current_children_=
false;
1621 while(this->node->first_child)
1622 this->node=this->node->first_child;
1628 template <
class T,
class tree_node_allocator>
1632 if(this->skip_current_children_ || this->node->last_child==0) {
1633 this->skip_current_children_=
false;
1634 while(this->node->prev_sibling==0)
1635 this->node=this->node->parent;
1636 this->node=this->node->prev_sibling;
1639 this->node=this->node->last_child;
1644 template <
class T,
class tree_node_allocator>
1652 template <
class T,
class tree_node_allocator>
1661 template <
class T,
class tree_node_allocator>
1671 template <
class T,
class tree_node_allocator>
1681 template <
class T,
class tree_node_allocator>
1685 while(this->node->first_child)
1686 this->node=this->node->first_child;
1692 template <
class T,
class tree_node_allocator>
1699 template <
class T,
class tree_node_allocator>
1706 template <
class T,
class tree_node_allocator>
1713 template <
class T,
class tree_node_allocator>
1720 template <
class T,
class tree_node_allocator>
1722 :
iterator_base(other.node), first_parent_(other.first_parent_)
1726 template <
class T,
class tree_node_allocator>
1732 if(this->node==0)
return;
1733 if(this->node->parent!=0)
1734 first_parent_=this->node->parent;
1736 find_leftmost_parent_();
1739 template <
class T,
class tree_node_allocator>
1747 first_parent_=tmppar;
1751 template <
class T,
class tree_node_allocator>
1755 if(this->node->next_sibling!=0) {
1756 this->node=this->node->next_sibling;
1758 if(this->node->parent==0 && this->node->next_sibling==0)
1775 template <
class T,
class tree_node_allocator>
1779 if(this->node->prev_sibling!=0) {
1780 this->node=this->node->prev_sibling;
1782 if(this->node->parent==0 && this->node->prev_sibling==0)
1799 template <
class T,
class tree_node_allocator>
1807 template <
class T,
class tree_node_allocator>
1815 template <
class T,
class tree_node_allocator>
1825 template <
class T,
class tree_node_allocator>
1840 template <
class T,
class tree_node_allocator>
1847 template <
class T,
class tree_node_allocator>
1854 template <
class T,
class tree_node_allocator>
1861 template <
class T,
class tree_node_allocator>
1867 template <
class T,
class tree_node_allocator>
1871 if(this->node==0)
return;
1872 if(this->node->parent!=0)
1873 parent_=this->node->parent;
1876 template <
class T,
class tree_node_allocator>
1880 this->node=this->node->next_sibling;
1884 template <
class T,
class tree_node_allocator>
1887 if(this->node) this->node=this->node->prev_sibling;
1890 this->node=parent_->last_child;
1895 template <
class T,
class tree_node_allocator>
1903 template <
class T,
class tree_node_allocator>
1911 template <
class T,
class tree_node_allocator>
1921 template <
class T,
class tree_node_allocator>
1931 template <
class T,
class tree_node_allocator>
1938 template <
class T,
class tree_node_allocator>
bool operator!=(const _Ht_iterator< _Val, _Nonconst_traits< _Val >, _Key, _HF, _ExK, _EqK, _All > &__x, const _Ht_iterator< _Val, _Const_traits< _Val >, _Key, _HF, _ExK, _EqK, _All > &__y)
fixed_depth_iterator & operator--()
tree_node * first_parent_
fixed_depth_iterator & operator+=(unsigned int)
fixed_depth_iterator & operator++()
void find_leftmost_parent_()
fixed_depth_iterator & operator-=(unsigned int)
bool operator()(const typename tree< T, tree_node_allocator >::iterator_base &one, const typename tree< T, tree_node_allocator >::iterator_base &two) const
sibling_iterator end() const
bool operator!=(const iterator_base &) const
std::bidirectional_iterator_tag iterator_category
bool operator==(const iterator_base &) const
bool skip_current_children_
unsigned int number_of_children() const
sibling_iterator begin() const
ptrdiff_t difference_type
post_order_iterator & operator+=(unsigned int)
post_order_iterator & operator-=(unsigned int)
post_order_iterator & operator++()
post_order_iterator & operator--()
pre_order_iterator & operator++()
pre_order_iterator & operator--()
pre_order_iterator & operator+=(unsigned int)
pre_order_iterator & operator-=(unsigned int)
tree_node * range_first() const
sibling_iterator & operator--()
tree_node * range_last() const
sibling_iterator & operator++()
sibling_iterator & operator+=(unsigned int)
sibling_iterator & operator-=(unsigned int)
tree_node_< T > * next_sibling
tree_node_< T > * last_child
tree_node_< T > * first_child
tree_node_< T > * prev_sibling
post_order_iterator begin_post() const
void erase_children(const iterator_base &)
bool equal_subtree(const iter &one, const iter &two) const
bool equal(const iter &one, const iter &two, const iter &three) const
sibling_iterator child(const iterator_base &position, unsigned int) const
void merge(sibling_iterator, sibling_iterator, sibling_iterator, sibling_iterator, bool duplicate_leaves=false)
pre_order_iterator iterator
iter insert_after(iter position, const T &x)
void copy_(const tree< T, tree_node_allocator > &other)
sibling_iterator previous_sibling(const iterator_base &) const
void sort(sibling_iterator from, sibling_iterator to, bool deep=false)
sibling_iterator next_sibling(const iterator_base &) const
tree_node_< T > tree_node
iter insert_subtree(iter position, const iterator_base &subtree)
tree_node_allocator alloc_
int depth(const iterator_base &) const
bool is_valid(const iterator_base &) const
post_order_iterator end_post() const
void operator=(const tree< T, tree_node_allocator > &)
iter append_child(iter position)
tree reroot(iterator newRoot)
unsigned int index(sibling_iterator it) const
bool is_in_subtree(const iterator_base &position, const iterator_base &begin, const iterator_base &end) const
iter replace(iter position, const T &x)
iter move_after(iter target, iter source)
iter append_children(iter position, sibling_iterator from, sibling_iterator to)
pre_order_iterator begin() const
iter insert(iter position, const T &x)
fixed_depth_iterator begin_fixed(const iterator_base &, unsigned int) const
unsigned int number_of_children(const iterator_base &) const
fixed_depth_iterator end_fixed(const iterator_base &, unsigned int) const
iter move_below(iter target, iter source)
iter reparent(iter position, sibling_iterator begin, sibling_iterator end)
void swap(sibling_iterator it)
pre_order_iterator set_head(const T &x)
iter flatten(iter position)
unsigned int number_of_siblings(const iterator_base &) const
tree subtree(sibling_iterator from, sibling_iterator to) const
pre_order_iterator end() const
iter move_before(iter target, iter source)
static bool is_valid(const char *num, int type, CONV_RESULT *cr)
static unsigned char depth[2 *(256+1+29)+1]
bool operator==(const CEquivRange &A, const CEquivRange &B)
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
static DLIST_TYPE *DLIST_NAME() last(DLIST_LIST_TYPE *list)
static DLIST_TYPE *DLIST_NAME() prev(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
static DLIST_TYPE *DLIST_NAME() next(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
void swap(NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair1, NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair2)
CVect2< NCBI_PROMOTE(int,U) > operator*(int v1, const CVect2< U > &v2)
#define NCBI_CDUTILS_EXPORT
CNcbiMatrix< T > & operator+=(CNcbiMatrix< T > &, const CNcbiMatrix< U > &)
global addition: matrix += matrix
CNcbiMatrix< T > & operator-=(CNcbiMatrix< T > &, const CNcbiMatrix< U > &)
global subtraction: matrix -= matrix
constexpr auto sort(_Init &&init)
constexpr bool empty(list< Ts... >) noexcept
void constructor(T1 *p, T2 &val)
double value_type
The numeric datatype used by the parser.
const struct ncbi::grid::netcache::search::fields::SIZE size
const CharType(& source)[N]
S & operator--(CNetRef< S > &r, int)
void flatten(size_t dimension_, const Int4 *const *scoreMatrix_, const double *const *prob_, size_t *dim_, Int4 **score_, double **p_, size_t dimension2_=0)
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
bool operator>(const typename tree< T, tree_node_allocator >::iterator_base &one, const typename tree< T, tree_node_allocator >::iterator_base &two)