コード例 #1
0
ファイル: list.c プロジェクト: ColumPaget/Alaya
void OrderedListAddJump(ListNode *From, ListNode *To)
{
int result;
static int depth=0;

if (! From) return;
if (! To) return;

depth++;
if (depth > 100) 
{
	printf("ERROR: OLJ DEEEP\n");
	exit(1);
}

if (From->Jump)
{
	result=strcmp(From->Jump->Tag, To->Tag);
//	if (result > 0)  OrderedListAddJump(From->Next,To);
//	else
	if (result < 0)
	{
	OrderedListAddJump(From->Next,From->Jump);
	From->Jump=To;
	}
}
else From->Jump=To;

depth--;
}
コード例 #2
0
void OrderedListAddJump(ListNode *From, ListNode *To)
{
int result;

if (! From) return;
if (! To) return;

if (From->Jump)
{
	result=strcmp(From->Jump->Tag, To->Tag);
	if (result > 0)  OrderedListAddJump(From->Next,To);
	else if (result==0)
	{
		 return;
	}
	else
	{
	OrderedListAddJump(From->Next,From->Jump);
	From->Jump=To;
	}
}
else From->Jump=To;
}
コード例 #3
0
ListNode *OrderedListAddNamedItem(ListNode *Head, const char *Name, void *Item)
{
ListNode *NewItem, *Prev, *Curr, *Start;
int count=0, jcount=0, result=-1;


if (! Head) return(NULL);
Prev=Head;
Curr=Head->Next;
Start=Curr;

while (Curr)
{
if (Curr->Jump)
{
	count=0;
	result=strcmp(Curr->Jump->Tag,Name);
	if (result < 0)
	{
		 Curr=Curr->Jump;
		 Prev=Curr->Prev;
		 jcount++;
		if (jcount > 5)
		{
		 OrderedListAddJump(Head->Next, Curr);
		 jcount=0;
		}
	Start=Curr->Next;
	}
}

if (Curr->Tag) result=strcmp(Curr->Tag,Name);
if (result > -1) break;

count++;
if (count > 100)
{
 OrderedListAddJump(Start, Curr);
 count=0;
 Start=Curr->Next;
}

Prev=Curr;
Curr=Curr->Next;
}

NewItem=(ListNode *) calloc(1,sizeof(ListNode)); 
NewItem->Item=Item;
NewItem->Prev=Prev;
NewItem->Next=Prev->Next;
Prev->Next=NewItem;
NewItem->Head=Prev->Head;
if (NewItem->Next) NewItem->Next->Prev=NewItem; /* Next might be NULL! */
ListIncrNoOfItems(NewItem);
if (StrLen(Name)) NewItem->Tag=CopyStr(NewItem->Tag,Name);


result=ListSize(NewItem);

if ((result % 2000)==0)
{
Curr=ListGetNth(Head,result / 2);
OrderedListAddJump(Head->Next, Curr);
}


return(NewItem);
}