# HG changeset patch # User michael # Date 1201122201 0 # Node ID 0839746f3fcfbcaa3d7a87167816006df8cee691 # Parent dcb08e8f3b2ea885d8abfb2bb5fbb29a6b9fc5fb Comment to explain how the add/remove core works. diff -r dcb08e8f3b2e -r 0839746f3fcf tree.c --- a/tree.c Mon Jan 21 13:33:18 2008 +0000 +++ b/tree.c Wed Jan 23 21:03:21 2008 +0000 @@ -75,6 +75,24 @@ if(!(t->state&1)){ if(t->state){ + /* The following code is equivalent to + if((*child)->state*2 == -t->state) + rotate(child, i^1); + rotate(tp, i); + + with rotate(): + static void rotate(AVTreeNode **tp, int i){ + AVTreeNode *t= *tp; + + *tp= t->child[i]; + t->child[i]= t->child[i]->child[i^1]; + (*tp)->child[i^1]= t; + i= 4*t->state + 2*(*tp)->state + 12; + t ->state= ((0x614586 >> i) & 3)-1; + (*tp)->state= ((*tp)->state>>1) + ((0x400EEA >> i) & 3)-1; + } + but such a rotate function is both bigger and slower + */ if((*child)->state*2 == -t->state){ *tp= (*child)->child[i^1]; (*child)->child[i^1]= (*tp)->child[i];