Exemple #1
0
/*
 *  タイムイベントヒープの先頭のノードの削除
 */
Inline void
tmevtb_delete_top(TEVTCB* p_tevtcb)
{
	uint_t	index;
	EVTTIM	event_time = TMEVT_NODE(p_tevtcb, p_tevtcb->last_index).time;

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

	/*
	 *  ルートノードに最後のノード(last_index + 1 の位置のノード)を
	 *  挿入し,それを適切な位置へ移動させる.実際には,最後のノードを
	 *  実際に挿入するのではなく,ルートノードが空ノードになるので,最
	 *  後のノードを挿入すべき位置へ向けて空ノードを移動させる.
	 */
	index = tmevt_down(p_tevtcb, 1, event_time);

	/*
	 *  最後のノードをindexの位置に挿入する.
	 */ 
	TMEVT_NODE(p_tevtcb, index) = TMEVT_NODE(p_tevtcb, p_tevtcb->last_index + 1);
	TMEVT_NODE(p_tevtcb, index).p_tmevtb->index = index;
}
/*
 *  delete the top time event in time event heap
 */
Inline void
tmevtb_delete_top(void)
{
	uint_t	index;
	EVTTIM	event_time = TMEVT_NODE(last_index).time;

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

	/*
	 *  search down to find righ position for last time event
	 *  in heap
	 */
	index = tmevt_down(1, event_time);

	/*
	 *  update info.
	 */ 
	TMEVT_NODE(index) = TMEVT_NODE(last_index + 1);
	TMEVT_NODE(index).p_tmevtb->index = index;
}
/*
 *  タイムイベントヒープの先頭のノードの削除
 */
Inline TMEVTB *
tmevtb_delete_top(void)
{
	TMEVTN	*p_tmevtn;
	TMEVTB	*p_top_tmevtb = p_top_tmevtn->p_tmevtb;
	EVTTIM	event_evttim;

	/*
	 *  削除によりタイムイベントヒープが空になる場合は何もしない.
	 */
	if (--p_last_tmevtn >= p_top_tmevtn) {
		/*
		 *  ルートノードに最後のノード(p_last_tmevtn + 1 の位置のノー
		 *  ド)を挿入し,それを適切な位置へ移動させる.実際には,最後
		 *  のノードを実際に挿入するのではなく,ルートノードが空ノード
		 *  になるので,最後のノードを挿入すべき位置へ向けて空ノードを
		 *  移動させる.
		 */
		event_evttim = (p_last_tmevtn + 1)->p_tmevtb->evttim;
		p_tmevtn = tmevt_down(p_top_tmevtn, event_evttim);

		/*
		 *  最後のノードをp_tmevtnの位置に挿入する.
		 */ 
		*p_tmevtn = *(p_last_tmevtn + 1);
		p_tmevtn->p_tmevtb->p_tmevtn = p_tmevtn;
	}
	return(p_top_tmevtb);
}
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;
}
/*
 *  タイムイベントヒープからの削除
 */
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;
}
Exemple #6
0
RELTIM
tmevtb_delete(TEVTCB *p_tevtcb, TMEVTB *p_tmevtb)
{
	uint_t	index = p_tmevtb->index;
	uint_t	parent;
	EVTTIM	event_time = TMEVT_NODE(p_tevtcb, p_tevtcb->last_index).time;
	EVTTIM	time;
	RELTIM	left_time;

	/*
	 *  タイムイベントまでの残り時間を計算
	 *  tmevt_leftim()とは異なり大きい方(current_timeとの差分)に丸める. 
	 */
	time = TMEVT_NODE(p_tevtcb, p_tmevtb->index).time;
	left_time = (RELTIM)(time - p_tevtcb->current_time);

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

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

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

	/*
	 *  最後のノードをindexの位置に挿入する.
	 */ 
	TMEVT_NODE(p_tevtcb, index) = TMEVT_NODE(p_tevtcb, (p_tevtcb->last_index) + 1);
	TMEVT_NODE(p_tevtcb, index).p_tmevtb->index = index;

	return(left_time);
}