Exemplo n.º 1
0
        void SplayTree::insert(node* n)
        {
            if (unlikely(header.parent == NULL))  // First element.
            {
                header.parent = header.child[LEFT] = header.child[RIGHT] = n;
                n->parent = n->child[LEFT] = n->child[RIGHT] = NULL;
            }
            else // Not first element.
            {
                // Find place to insert node and insert it.
                node* insert_location = header.parent;
                __find(insert_location, n);
                __insert(insert_location, n);

                // Fix up header nodes.
                header.child[LEFT] = leftmost(header.child[LEFT]);
                header.child[RIGHT] = rightmost(header.child[RIGHT]);

                // Splay new node.
                splay(n);
            }

            // Increment size count.
            (header_n()->data)++;
        }
Exemplo n.º 2
0
 virtual bool insert( param_key key, param_type args )
 {
     //------------------------------------------------------------------
     // check key
     //------------------------------------------------------------------
     HSlot       *slot = 0;
     const size_t hkey = hash(key);
     if( (slots>0) && (0!=__find(key, hkey, slot)) ) return false;
     
     //------------------------------------------------------------------
     // check memory/insert
     //------------------------------------------------------------------
     if( klist.size >= itmax )
     {
         map tmp( container::next_capacity(itmax), as_capacity );
         __duplicate_into(tmp);
         tmp.__insert(key,hkey,args);
         swap_with(tmp);
     }
     else
     {
         __insert(key,hkey,args);
     }
     return true;
 }
Exemplo n.º 3
0
Arquivo: avl.c Projeto: Emeraude/AVL
void avl_insert(t_avl *const avl, void *const val) {
  if (!avl->hook_cmp) {
    fprintf(stderr, "%s: Warning: no cmp hook defined. Using default comparators.\n", __FUNCTION__);
    avl->hook_cmp = __default_hook_cmp;
  }
  __insert(avl, (t_node **)&avl->root, val);
}
Exemplo n.º 4
0
Arquivo: avl.c Projeto: Emeraude/AVL
/* insertion */
static void __insert(t_avl const *const avl, t_node **const root, void *val) {
  if (*root == nil) {
    if (!(*root = malloc(sizeof(**root)))) {
      perror("malloc");
      return;
    }
    (*root)->val = val;
    (*root)->height = 1;
    (*root)->node[0] = nil;
    (*root)->node[1] = nil;
  }
  else if (avl->hook_cmp(val ,(*root)->val)) {
    __insert(avl, &(*root)->node[avl->hook_cmp(val, (*root)->val) < 0], val);
    balance(avl, root);
  }
}
Exemplo n.º 5
0
        void SplayTree::__insert(node* t, node* n)
        {
            node*& child = (0 > (*compare_functor)(this, n, t)) ?
                                    t->child[LEFT] : t->child[RIGHT];

            if (likely(NULL == child)) // Assumption is the subtree hint is
                                       // correct, so this should be NULL.
            {
                // Link node into "child" slot.
                child = n;
                n->parent = t;
            }
            else
            {
                // Subtree hint was wrong, recurse tree.
                __insert(n, child);
            }
        }
Exemplo n.º 6
0
void seeki_add(void *handle, struct io *iop)
{
    struct seeki *sip = handle;
    char rw = IOP_READ(iop) ? 'r' : 'w';
    long long dist = seek_dist(sip, iop);
    double tstamp = BIT_TIME(iop->t.time);
    FILE *fp = IOP_READ(iop) ? sip->rfp : sip->wfp;

    if (fp)
        fprintf(fp, "%15.9lf %13lld %c\n", tstamp, dist, rw);
    if (sip->cfp)
        fprintf(sip->cfp, "%15.9lf %13lld %c\n", tstamp, dist, rw);

    dist = llabs(dist);
    sip->tot_seeks++;
    sip->total_sectors += dist;
    __insert(&sip->root, dist);

    sps_add(sip, tstamp);
}
Exemplo n.º 7
0
int main()
{
  AAutoPtr<AObjectContainer> pns(new AObjectContainer("root"));

  try
  {
    __populate(*pns.get());
    //test_iterator();
    __insert(*pns.get());
    //__display(*pns);
  }
  catch(AException& ex)
  {
    std::cout << ex.what() << std::endl;
  }
  catch(...)
  {
    std::cout << "Unknown exception caught!" << std::endl;
  }

  return 0;
}
Exemplo n.º 8
0
	iterator insert(Container &container)
	{
		return __insert(container.begin(), container.end());
	}