コード例 #1
0
// adjust balance for a double rotate left
void AVLTreeIndex::adjustRL(AVLTreeNode *last, AVLTreeNode *first)
{
    if (last == root) last->balance = balanced;
    else if (first->key > last->parent->key) {
        last->balance = biasleft;
        adjustBalance(last->parent->right, first);
    } else {
        last->balance = balanced;
        last->parent->right->balance = biasright;
        adjustBalance(last, first);
    }
}
コード例 #2
0
ファイル: core.hpp プロジェクト: Brunnis/bsnes-mercury
void DSP::read(signed channel[]) {
  adjustVolume();
  adjustBalance();

  for(unsigned c = 0; c < settings.channels; c++) {
    channel[c] = clamp(settings.precision, output.read(c) * settings.intensity);
  }
  output.rdoffset++;
}
コード例 #3
0
void AVLTreeIndex::restoreBalance(AVLTreeNode *parent, AVLTreeNode *newNode)
{
    // case 1: parent DNE, newNode unbalances
    if (parent == NULL) {
        if (newNode->key < root->key) root->balance = biasleft; // newNode inserted left of root
        else root->balance = biasright; // newNode inserted right of root
        adjustBalance(root, newNode);
    }

    // case 2: insertion of newNode in opposite subtree of parent, balances parent
    else if (((parent->balance == biasleft) && (newNode->key.compare(parent->key) > 0)) ||
             ((parent->balance == biasright) && (newNode->key.compare(parent->key) < 0))) {
        parent->balance = balanced;
        adjustBalance(parent, newNode);
    }

    // case 3: insertion of newNode in right child of parent
    else if (parent->balance == biasright) {
        if (newNode->key > parent->right->key) { // insertion into right subtree of right child, single rotation left
            parent->balance = balanced;
            rotateLeft(parent);
            adjustBalance(parent->parent, newNode);
        } else if (newNode->key < parent->right->key) { // insertion into left subtree of right child, double rotation left
            rotateRight(parent->right);
            rotateLeft(parent);
            adjustRL(parent, newNode);
        }
    }

    // case 4: insertion of newNode in left child of parent
    else if (parent->balance == biasleft) {
        if (newNode->key < parent->left->key) { // insertion into left subtree of left child, single rotation right
            parent->balance = balanced;
            rotateRight(parent);
            adjustBalance(parent->parent, newNode);
        } else if (newNode->key < parent->right->key) { // insertion into right subtree of left child, double rotation right
            rotateLeft(parent->left);
            rotateRight(parent);
            adjustLR(parent, newNode);
        }
    }
}
コード例 #4
0
ファイル: treeset.c プロジェクト: crippledjosh/Coding
static TNode *insertBalance(TNode *root, int dir) {
   TNode *n = root->link[dir];
   int bal = (dir == 0) ? -1 : +1;

   if (n->balance == bal) {
      root->balance = n->balance = 0;
      root = singleRotate(root, !dir);
   } else {	/* n->balance == -bal */
      adjustBalance(root, dir, bal);
      root = doubleRotate(root, !dir);
   }
   return root;
}
コード例 #5
0
ファイル: treeset.c プロジェクト: crippledjosh/Coding
static TNode *removeBalance(TNode *root, int dir, int *done) {
   TNode *n = root->link[!dir];
   int bal = (dir == 0) ? -1 : +1;

   if (n->balance == -bal) {
      root->balance = n->balance = 0;
      root = singleRotate(root, dir);
   } else if (n->balance == bal) {
      adjustBalance(root, !dir, -bal);
      root = doubleRotate(root, dir);
   } else {	/* n->balance == 0 */
      root->balance = -bal;
      n->balance = bal;
      root = singleRotate(root, dir);
      *done = 1;
   }
   return root;
}