コード例 #1
0
void
RemoveRand
	(
	JHashTable< JStrValue<int> >* const table,
	const JSize                 listLength,
	const JHashValue*     const hashList,
	const JStrValue<int>* const valueList,
	      int*            const countList
	)
{
	const JIndex firstEl = gRand.UniformLong(0, listLength-1);
	JIndex el = firstEl;
	while (countList[el] == 0)
		{
		++el;
		if (el == firstEl)
			{
			if (table->GetElementCount() != 0)
				{
				PrintError(__LINE__);
				}
			return;
			}
		}

	RemoveElement(el, table, kElementNum, hashList, valueList, countList);
}
コード例 #2
0
void
JXTipOfTheDayDialog::ParseTips()
{
	const JString& data = JGetString(kStringID);

	itsTipList->CleanOut();

	const JSize len = strlen(kDelimiter);

	JIndex j = 1, i = j;
	while (data.LocateNextSubstring(kDelimiter, &j))
		{
		if (j > i)
			{
			AddTip(data.GetSubstring(i, j-1));
			}

		j += len;
		i  = j;
		}

	if (i <= data.GetLength())
		{
		AddTip(data.GetSubstring(i, data.GetLength()));
		}

	assert( !itsTipList->IsEmpty() );

	itsTipIndex = theRandomGenerator.UniformLong(1, itsTipList->GetElementCount());
	DisplayTip();
}
コード例 #3
0
void
SearchRand
	(
	const JHashTable< JStrValue<int> >* const table,
	const JSize                 listLength,
	const JHashValue*     const hashList,
	const JStrValue<int>* const valueList,
	const int*            const countList
	)
{
	const JIndex el = gRand.UniformLong(0, listLength-1);
	SearchElement(el, table, listLength, hashList, valueList, countList);
}
コード例 #4
0
void
RemoveElement
	(
	const JSize el,
	JHashTable< JStrValue<int> >* const table,
	const JSize                 listLength,
	const JHashValue*     const hashList,
	const JStrValue<int>* const valueList,
	      int*            const countList
	)
{
	JHashCursor< JStrValue<int> > cursor(table, hashList[el]);
	JSize count = 0;
	while ( cursor.NextHash() )
		{
		++count;
		if ( !cursor.IsFull() || cursor.GetHashValue() != hashList[el])
			{
			PrintError(__LINE__);
			}
		}

	if (count == 0)
		{
		return;
		}

	const JSize deleteNum = gRand.UniformLong(1, count);

	cursor.Reset();
	for (JIndex i=1;i<=deleteNum;i++)
		{
		if (!cursor.NextHash() )
			{
			PrintError(__LINE__);
			cout << "   Count = " << count << ", deleteNum = " << deleteNum << endl;
			cout << "   Error on cycle " << i << endl;
			return;
			}
		}

	cursor.Remove();
	--countList[el];
}