예제 #1
0
void
tmevtb_delete(TMEVTB *p_tmevtb)
{
	uint_t	index = p_tmevtb->index;
	uint_t	parent;
	EVTTIM	event_time = TMEVT_NODE(last_index).time;

	/*
	 *  last_index--
	 *  if last_index == 0
	 *  do nothing.
	 */
	if (--last_index == 0) {
		return;
	}

	/*
	 *
	 *  insert the last time event into the position of deleted time
	 *  event. In fact, the insert does not happened. The position of 
	 *  deleted time will be a empty node in time event heap. Then this
	 *  empty node will be moved to a right position which is the right
	 *  position of the last time event. 
	 * 
	 *  If the event time of the last time event is earlier than deleted
	 *  time event's parent, then search up, or search down.
	 *
	 */
	if (index > 1 && EVTTIM_LT(event_time,
								TMEVT_NODE(parent = PARENT(index)).time)) {
		/*
		 *  if deleted time event's parent is not earlier than last time event
		 *  in heap, change parent's position and update info.
		 * 
		 */
		TMEVT_NODE(index) = TMEVT_NODE(parent);
		TMEVT_NODE(index).p_tmevtb->index = index;

		/*
		 *  then search up to find the right position for the last time event in heap
		 *  from parent's position
		 */
		index = tmevt_up(parent, event_time);
	}
	else {
		/*
		 *  search down to find right position for last time event in heap.
		 */
		index = tmevt_down(index, event_time);
	}

	/*
	 * update the last time event's info
	 */ 
	TMEVT_NODE(index) = TMEVT_NODE(last_index + 1);
	TMEVT_NODE(index).p_tmevtb->index = index;
}
예제 #2
0
static void _sio_timer_adjust_heap(struct sio_timer_manager *st_mgr, struct sio_timer *timer)
{
    uint64_t parent = PARENT(timer);
    
    if (parent && timer->expire < st_mgr->heap_nodes[parent]->expire) 
        _sio_timer_upheap(st_mgr, timer);
    else
        _sio_timer_downheap(st_mgr, timer);
}
예제 #3
0
HWND bookSetup( ULONG idInitialPage )
{
    HWND hwndFrame;

    if( hwndBook )
    {
        hwndFrame = PARENT( hwndBook );

        // For some reason it is necessary to restore the notebook before
        // setting the frame as the active window if the frame is being
        // restored from a minimized state.

        WinSetWindowPos( hwndBook, NULLHANDLE, 0, 0, 0, 0,
                         SWP_SHOW | SWP_RESTORE );
        WinSetWindowPos( hwndFrame, NULLHANDLE, 0, 0, 0, 0,
                         SWP_SHOW | SWP_RESTORE | SWP_ACTIVATE );
    }
    else
    {
        FRAMECDATA fcdata;

        memset( &fcdata, 0, sizeof fcdata );
        fcdata.cb            = sizeof( FRAMECDATA );
        fcdata.flCreateFlags = FRAME_FLAGS;
        fcdata.idResources   = ID_NBFRAME;

        hwndFrame = WinCreateWindow( HWND_DESKTOP, WC_FRAME, NULL, WS_ANIMATE,
                                     0, 0, 0, 0, NULLHANDLE, HWND_TOP,
                                     ID_NBFRAME, &fcdata, NULL );
        if( hwndFrame )
        {
            pfnwpFrame = WinSubclassWindow( hwndFrame, wpNBFrame );
            if( pfnwpFrame )
                if( CreateNotebookWindow( hwndFrame ) )
                    WinSetWindowText( hwndFrame, BOOK_TITLE );
                else
                {
                    WinDestroyWindow( hwndFrame );
                    hwndFrame = NULLHANDLE;
                }
            else
            {
                WinDestroyWindow( hwndFrame );
                Msg( "bookSetup WinSubclassWindow RC(%X)", HWNDERR(hwndFrame) );
                hwndFrame = NULLHANDLE;
            }
        }
        else
            Msg( "bookSetup WinCreateWindow of frame window RC(%X)", HABERR(0));
    }

    if( hwndBook )
        TurnToPage( idInitialPage );

    return hwndFrame;
}
예제 #4
0
/*****************************************************************************
 * heap_build
 *
 * Build a heap from an unordered array.
 *****************************************************************************/
void heap_build( heap_t *heap )
{
    GLint	i;

    heap->size = heap->length;

    for ( i = PARENT( heap->length ) ; i >= 0 ; i-- ) {
	heapify( heap, i );
    }
}
예제 #5
0
void priority(BinHeap *bh, int data, int newPriority){
    long i = 0, k;
    while (i < bh->size){
        if (bh->A[i].data == data){
            printf("sosi%d \n", newPriority);
            if (newPriority < bh->A[i].priority){
                bh->A[i].priority = newPriority;
                k = i;
                while(k && newPriority < bh->A[PARENT(k)].priority) {
                    bh->A[k] = bh->A[PARENT(k)];
                    k = PARENT(k);
                }
                bh->A[k].priority = newPriority;
                bh->A[k].data = data;
            }
        }
        i++;
    }
}
예제 #6
0
void insert_heap(puzzle b)
{
   puzzle tmp;
   int    index;

   if (heap_size == MAX_HEAP_SIZE) {
      printf ("Heap overflow\n");
      exit(-1);
   }
   heap[heap_size] = b;
   index = heap_size;
   heap_size++;
   while ((index > 0) && superior(index, PARENT(index))) {
      tmp = heap[index];
      heap[index] = heap[PARENT(index)];
      heap[PARENT(index)] = tmp;
      index = PARENT(index);
   }
}
예제 #7
0
파일: pqueue.c 프로젝트: patseb/scgl
void
pqueue_enqueue(pqueue_t *queue, const void *data) {
	size_t i;
	void *tmp = NULL;
	if (queue == NULL || queue->size >= queue->capacity)
		return;
	/* adds element last */
	queue->data[queue->size] = (void*)data;
	i = queue->size;
	queue->size++;

	/* the new element is swapped with its parent as long as its precedence is higher */
	while(i > 0 && queue->cmp(queue->data[i], queue->data[PARENT(i)]) > 0) {
		tmp = queue->data[i];
		queue->data[i] = queue->data[PARENT(i)];
		queue->data[PARENT(i)] = tmp;
		i = PARENT(i);
	}
}
예제 #8
0
static void
dvb_flush			(vbi_capture *		cap)
{
	vbi_capture_dvb *dvb = PARENT (cap, vbi_capture_dvb, capture);

	vbi_dvb_demux_reset (dvb->demux);

	dvb->bp = dvb->pes_buffer;
	dvb->b_left = 0;
}
예제 #9
0
void DominatorTree::debugPrint()
{
   for (int i = 0; i < count; ++i) {
      INFO("SEMI(%i) = %i\n", i, SEMI(i));
      INFO("ANCESTOR(%i) = %i\n", i, ANCESTOR(i));
      INFO("PARENT(%i) = %i\n", i, PARENT(i));
      INFO("LABEL(%i) = %i\n", i, LABEL(i));
      INFO("DOM(%i) = %i\n", i, DOM(i));
   }
}
예제 #10
0
파일: MiniHeap.cpp 프로젝트: xvly/fish
void up(struct minheap * mh,int index) 
{
	int parent = PARENT(index);
	while(parent >= 1)
	{
		assert(mh->elts[index]);
		assert(mh->elts[parent]);
		if (mh->less(mh->ud,mh->elts[index],mh->elts[parent]))
		{
			swap(mh,index,parent);
			index = parent;
			parent = PARENT(index);
		}
		else 
		{
			break;
		}
	}
}
예제 #11
0
/* BSTreeDepth
 *  returns number of layers in b-tree
 *
 *  if "exact" is 1, then the maximum
 *  depth is returned. otherwise, the depth of
 *  an arbitrary leaf node is returned
 */
LIB_EXPORT uint32_t CC BSTreeDepth ( const BSTree *bt, bool exact )
{
    BSTNode *p;
    uint32_t depth;

    if ( bt == NULL || bt -> root == NULL )
        return 0;

    depth = 1;

    if ( exact )
    {
        for ( p = FirstNode ( bt ); p != NULL; p = BSTNodeNext ( p ) )
        {
            BSTNode *q;
            unsigned int ndepth;

            if ( p -> child [ 0 ] != NULL || p -> child [ 1 ] != NULL )
                continue;

            for ( ndepth = 1, q = PARENT ( p ); q != NULL; q = PARENT ( q ) )
                ++ ndepth;

            if ( ndepth > depth )
                depth = ndepth;
        }
    }
    else
    {
        for ( p = bt -> root;; ++ depth )
        {
            if ( p -> child [ 0 ] != NULL )
                p = p -> child [ 0 ];
            else if ( p -> child [ 1 ] != NULL )
                p = p -> child [ 1 ];
            else
                break;
        }
    }

    return depth;
}
예제 #12
0
파일: pq.c 프로젝트: rainly/beanstalkd
static void
bubble_up(pq q, unsigned int k)
{
    int p;

    if (k == 0) return;
    p = PARENT(k);
    if (cmp(q, p, k) <= 0) return;
    swap(q, k, p);
    bubble_up(q, p);
}
예제 #13
0
void DominatorTree::buildDFS(Graph::Node *node)
{
   SEMI(node->tag) = node->tag;

   for (Graph::EdgeIterator ei = node->outgoing(); !ei.end(); ei.next()) {
      if (SEMI(ei.getNode()->tag) < 0) {
         buildDFS(ei.getNode());
         PARENT(ei.getNode()->tag) = node->tag;
      }
   }
}
예제 #14
0
static
bool CC BSTreeContains ( const BSTNode *root, const BSTNode *n )
{
    while ( n != NULL )
    {
        if ( n == root )
            return true;
        n = PARENT ( n );
    }
    return false;
}
예제 #15
0
// Adds a timer to the heap, using timer_node data. Passed
// timer_node is first unused element in timer_heap array.
__forceinline void TimerAddNode(timer_node *t)
{
   if (numActiveTimers == 0 || timer_heap[0]->time > t->time)
   {
      // We're making a new first-timer, so the time main loop should wait might
      // have changed, so have it break out of loop and recalibrate
      MessagePost(main_thread_id, WM_BLAK_MAIN_RECALIBRATE, 0, 0);
   }

   // Start node off at end of heap.
   int i = numActiveTimers++;
   timer_heap[i]->heap_index = i;

   // Push node up if necessary.
   while (i > 0 && timer_heap[i]->time < timer_heap[PARENT(i)]->time)
   {
      TimerSwapIndex(i, PARENT(i));
      i = PARENT(i);
   }
}
예제 #16
0
void TasNoeud_monter(TasNoeud *tas, int k) {
    int mincout, parent;
    if (k > 0) { // Condition de terminaison
        parent = PARENT(k);
        mincout = parent;
        if (tas->noeuds[k].cout < tas->noeuds[mincout].cout) { // Autre condition de terminaison
            ECHANGER(tas, k, mincout);
            TasNoeud_monter(tas, mincout); // Continuer tant que le tas n'est pas ordonné
        }
    }
}
예제 #17
0
Node *malloc_node(Interval key)
{
	Node *n = (Node *)malloc(sizeof(Node));
	assert(n);
	KEY(n) = key;
	SET_RED(n);
	PARENT(n) = LEFT(n) = RIGHT(n) = &NIL_NODE;
	n->max = HIGH(key);

	return n;
}
예제 #18
0
Node *malloc_node(int key)
{
	Node *n = (Node *)malloc(sizeof(Node));
	assert(n);
	KEY(n) = key;
	SET_RED(n);
	SIZE(n) = 1;
	PARENT(n) = LEFT(n) = RIGHT(n) = &NIL_NODE;

	return n;
}
예제 #19
0
bool
insert(Any_Type a, struct Heap *h)
{
	u_long          i;

	if (is_heap_full(h))
		return false;

	i = ++h->num_elements;

	/*
	 * find the correct place to insert
	 */
	while ((i > 1) && (*h->compare) (h->storage[PARENT(i)], a)) {
		h->storage[i] = h->storage[PARENT(i)];
		i = PARENT(i);
	}
	h->storage[i] = a;
	return true;
}
예제 #20
0
파일: blocktree.c 프로젝트: Chaduke/bah.mod
/* create_block_tree:
 * Construct block tree by peeling nodes from block list in state.
 * When done, return root. The block list is empty
 * FIX: use largest block as root
 */
block_t *createBlocktree(Agraph_t * g, circ_state * state)
{
    block_t *bp;
    block_t *next;
    block_t *root;
    int min;
    /* int        ordercnt; */

    find_blocks(g, state);

    bp = state->bl.first;	/* if root chosen, will be first */
    /* Otherwise, just pick first as root */
    root = bp;

    /* Find node with minimum VAL value to find parent block */
    /* FIX: Should be some way to avoid search below.               */
    /* ordercnt = state->orderCount;  */
    for (bp = bp->next; bp; bp = next) {
	Agnode_t *n;
	Agnode_t *parent;
	Agnode_t *child;
	Agraph_t *subg = bp->sub_graph;

	child = n = agfstnode(subg);
	min = VAL(n);
	parent = PARENT(n);
	for (n = agnxtnode(subg, n); n; n = agnxtnode(subg, n)) {
	    if (VAL(n) < min) {
		child = n;
		min = VAL(n);
		parent = PARENT(n);
	    }
	}
	SET_PARENT(parent);
	CHILD(bp) = child;
	next = bp->next;	/* save next since list insertion destroys it */
	appendBlock(&(BLOCK(parent)->children), bp);
    }
    initBlocklist(&state->bl);	/* zero out list */
    return root;
}
예제 #21
0
파일: trees.c 프로젝트: mathemaphysics/util
int bstree_right_rotate( bstree_t *tree_in, long idx_in )
{
	long x,y;
	x = idx_in;
	y = tree_in->start[idx_in].left;
	if( PARENT(x) != -1 )
	{
		if( PARENT_LEFT(x) == x )
			PARENT_LEFT(x) = y;
		else
			PARENT_RIGHT(x) = y;
	}
	else
		tree_in->root = y;
	PARENT(y) = PARENT(x);
	PARENT(x) = y;
	LEFT(x) = RIGHT(y);
	if( RIGHT(y) != -1 )
		RIGHT_PARENT(y) = x;
	RIGHT(y) = x;
}
예제 #22
0
파일: heap.c 프로젝트: QMonkey/ACM-ICPC
void backtrack(int32_t *begin,int32_t *end,int32_t *current)
{
	if(begin != current)
	{
		int32_t *parent = PARENT(begin,current);
		if(*parent < *current)
		{
			swap(parent,current);
			backtrack(begin,end,parent);
		}
	}
}
예제 #23
0
// Fixes the heap after a timer has been deleted or modified.
__inline void TimerHeapHeapify(int index)
{
   int i = index;
   while (i > 0 && timer_heap[i]->time < timer_heap[PARENT(i)]->time)
   {
      TimerSwapIndex(i, PARENT(i));
      i = PARENT(i);
   }
   do
   {
      int min = i;
      if (LCHILD(i) < numActiveTimers && timer_heap[LCHILD(i)]->time <= timer_heap[min]->time)
         min = LCHILD(i);
      if (RCHILD(i) < numActiveTimers && timer_heap[RCHILD(i)]->time < timer_heap[min]->time)
         min = RCHILD(i);
      if (min == i)
         break;
      TimerSwapIndex(i, min);
      i = min;
   } while (true);
}
예제 #24
0
/**
 * * Adds a new element to the Priority Queue .
 * */
void pqueue_enqueue(PQueue *q, const void *data) {
    size_t i;
    void *tmp = NULL;
    NP_CHECK(q);
    if (q->size >= q->capacity) {
        DEBUG("Priority Queue is full. Cannot add another element .");
        return;
    }
    /* Adds element last */
    q->data[q->size] = (void*) data;
    i = q->size;
    q->size++;
    /* The new element is swapped with its parent as long as its
     *     precedence is higher */
    while(i > 0 && q->cmp(q->data[i], q->data[PARENT(i)]) < 0) {
        tmp = q->data[i];
        q->data[i] = q->data[PARENT(i)];
        q->data[PARENT(i)] = tmp;
        i = PARENT(i);
    }
}
void ternary_heapify(void *base,
                     size_t nmemb,
                     size_t size,
                     compare_fun3 compare,
                     void *arg) {
  size_t max_index = nmemb-1;
  size_t start = PARENT(max_index);
  for (long i = start; i >= 0; i--) {
    size_t parent = (size_t) i;
    ternary_sift_down(base, parent, size, max_index, compare, arg);
  }
}
예제 #26
0
파일: heap.c 프로젝트: kaniblu/dslib
void bheap_add(bheap *heap, void *key, void *value)
{
	int c = heap->count + 1, p;
	keyval *data = heap->data;
    keyval tmp;

    data[c].key = key;
	data[c].value = value;

	p = PARENT(c);
	while (p > 0) {
		if (heap->compare(data[p].key, data[c].key) < 0)
			break;
		else
			SWAP(data, p, c, tmp);
		c = p;
		p = PARENT(p);
	}

	heap->count++;
}
예제 #27
0
파일: heap.c 프로젝트: srsbsns/libsrsbsns
static void
heap_rdump(heap_t h, size_t node, int depth, heap_dump_fn df)
{
	if (node >= h->treesz || node >= h->next || !h->tree[node])
		return;

	heap_rdump(h, LEFT(node), depth+1, df);
	for (int i = 0; i < depth; i++)
		fputs("  ", stderr);
	fputs("``", stderr);
	df(h->tree[node]);
	fprintf(stderr, "'' [%zu; %12p (p:%12p: ``",
	    node, h->tree[node], h->tree[PARENT(node)]);
	if (node)
		df(h->tree[PARENT(node)]);
	else
		fprintf(stderr, "(root)");
	fprintf(stderr, "'')]");
	fputs("\n", stderr);
	heap_rdump(h, RIGHT(node), depth+1, df);
}
예제 #28
0
파일: heap.c 프로젝트: kgadek/kpfp
int kpfp_heap_push(struct kpfp_heap *heap, int val) {
	int i, l, p;
	if(heap->size == heap->max)
		return val-1;
	heap->tab[i=(heap->size)++] = val;
	while(i>0 && heap->tab[p=PARENT(i)] < heap->tab[i]) { /*swap*/
		l = heap->tab[i];
		heap->tab[i] = heap->tab[p];
		heap->tab[i=p] = l;
	}
	return val;
}
예제 #29
0
/*
 *  タイムイベントヒープからの削除
 */
Inline void
tmevtb_delete(TMEVTB *p_tmevtb)
{
	TMEVTN	*p_tmevtn = p_tmevtb->p_tmevtn;
	TMEVTN	*p_parent;
	EVTTIM	event_evttim;

	/*
	 *  削除によりタイムイベントヒープが空になる場合は何もしない.
	 */
	if (--p_last_tmevtn < p_top_tmevtn) {
		return;
	}

	/*
	 *  削除したノードの位置に最後のノード(p_last_tmevtn + 1 の位置の
	 *  ノード)を挿入し,それを適切な位置へ移動させる.実際には,最後
	 *  のノードを実際に挿入するのではなく,削除したノードの位置が空ノー
	 *  ドになるので,最後のノードを挿入すべき位置へ向けて空ノードを移
	 *  動させる.
	 *
	 *  最後のノードのイベント発生時刻が,削除したノードの親ノードのイ
	 *  ベント発生時刻より前の場合には,上に向かって挿入位置を探す.そ
	 *  うでない場合には,下に向かって探す.
	 */
	event_evttim = (p_last_tmevtn + 1)->p_tmevtb->evttim;
	if (p_tmevtn > p_top_tmevtn
			&& EVTTIM_LT(event_evttim,
						(p_parent = PARENT(p_tmevtn))->p_tmevtb->evttim)) {
		/*
		 *  親ノードをp_tmevtnの位置に移動させる.
		 */
		*p_tmevtn = *p_parent;
		p_tmevtn->p_tmevtb->p_tmevtn = p_tmevtn;

		/*
		 *  削除したノードの親ノードから上に向かって挿入位置を探す.
		 */
		p_tmevtn = tmevt_up(p_parent, event_evttim);
	}
	else {
		/*
		 *  削除したノードから下に向かって挿入位置を探す.
		 */
		p_tmevtn = tmevt_down(p_tmevtn, event_evttim);
	}

	/*
	 *  最後のノードをp_tmevtnの位置に挿入する.
	 */ 
	*p_tmevtn = *(p_last_tmevtn + 1);
	p_tmevtn->p_tmevtb->p_tmevtn = p_tmevtn;
}
예제 #30
0
파일: block.c 프로젝트: Chaduke/bah.mod
void printBlocklist(blocklist_t * snl)
{
    block_t *bp;
    for (bp = snl->first; bp; bp = bp->next) {
	Agnode_t *n;
	char *p;
	Agraph_t *g = bp->sub_graph;
	fprintf(stderr, "block=%s\n", g->name);
	for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
	    Agedge_t *e;
	    if (PARENT(n))
		p = PARENT(n)->name;
	    else
		p = "<nil>";
	    fprintf(stderr, "  %s (%d %s)\n", n->name, VAL(n), p);
	    for (e = agfstedge(g, n); e; e = agnxtedge(g, e, n)) {
		fprintf(stderr, "    %s--%s\n", e->tail->name,
			e->head->name);
	    }
	}
    }
}