Exemple #1
0
int main()
{
	Hash ha[100];
	int m, i = 0, n = 1,key;
	int adr, q;
	char ch;
	int a[100];
	scanf("%d", &m);
	scanf("%d%c", &a[i], &ch);
	getchar();
	while (ch==' ')
	{
		i++;
		scanf("%d%c", &a[i], &ch);
		n++;
	}
	scanf("%d", &key);
	CreateHash(ha, a, n, m, m);
	adr = SearchHT(ha, m, key);
	if (adr != -1)
		printf("%d, %d", adr, ha[adr].count);
	else
		printf("-1");
	return 0;
}
Exemple #2
0
protected func Construction() {
	if(GetID() == SAVS) {
		DebugLog("ERROR: Dieses Objekt darf nicht erstellt werden");
		RemoveObject();
	}
	hFillLevel = CreateHash();
	UpdatePicture();
	return _inherited(...);
}
int main () {
	hash_table hash_array;
	hash_table* hash_info = &hash_array;
	hash_info->size = 256;
	CreateHash(hash_info);
	if (TestAddFunction(hash_info) != 0) printf("Failed in TestAddFunction");
	if (TestSearchFunction(hash_info) != 0) printf("Failed in TestSearchFunction");
	if (TestRemoveFunction(hash_info) != 0) printf("Failed in TestRemoveFunction");
	if (TestIterators(hash_info) != 0) printf("Failed in TestIterators");
	hash_info = ResizeHash(hash_info);
	if (hash_info == NULL) printf("Failed in ResizeHash");
	CleanMemory(hash_info);
	return 0;
}
int main(){
    /*
printf("\nPrime numb:\n\n");

printf("\n\n");
getch();
*/
//it populates array for prime numbers

PopulateP();

//
printf("\nEnter the number of records : ");
int n,data;
scanf("%d",&n);
HNode* hash=CreateHash(n);

printf("\nSize %d count %d",hash->size,hash->count);

getch();
printf("\nEnter the number of elements in the array : ");
int m,i;
scanf("%d",&m);

int* Array=(int*)malloc(sizeof(int)*m);
printf("\nEnter the elements in the array \n");
for(i=0;i<m;i++){
scanf("%d",&Array[i]);
}

printf("\nElements added\n");

printf("\nEnter the value of K : ");
int K;
scanf("%d",&K);
printf("\nPress enter to check if duplicate exits within K distance\n");
getch();
int result=DuplicateAtK(hash,Array,m,K);

if(result){
printf("\nYes duplicate exists\n");
}else{
printf("\No passed\n");
}

return 0;
}
Exemple #5
0
/*
====================
sdTraceSurface::sdTraceSurface
====================
*/
sdTraceSurface::sdTraceSurface( const idDrawVert *verts, const int numVerts, const vertIndex_t *indexes, const int numIndexes, const int hashBinsPerAxis ) :
	verts( verts ),
	numVerts( numVerts ),
	indexes( indexes ),
	numIndexes( numIndexes ) {

	binsPerAxis = idMath::FloorPowerOfTwo( hashBinsPerAxis );
	binLinks = NULL;

	// find the bounding volume for the mesh
	SIMDProcessor->MinMax( _bounds.GetMins(), _bounds.GetMaxs(), verts, numVerts );
	_bounds.ExpandSelf( 64.f );

	// create face planes
	facePlanes = (idPlane*)Mem_AllocAligned( (numIndexes / 3) * sizeof(idPlane), ALIGN_16 );
	SIMDProcessor->DeriveTriPlanes( facePlanes, verts, numVerts, indexes, numIndexes );

	CreateHash();
}
void CDamageEffectController::Init(CActor* actor)
{
	if (CKVoltEffect::s_hashId == 0) //once initialised it can't be 0
	{
		CKVoltEffect::s_hashId = CreateHash("KVoltFX");
		CTinnitusEffect::s_hashId = CreateHash("TinnitusFx");
		CEntityTimerEffect::s_hashId = CreateHash("TimerFX");
	}

	IGameRules* pGameRules = g_pGame->GetGameRules();
	m_ownerActor = actor;

	const IItemParamsNode* actorParams = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActorParams(actor->GetEntityClassName());
	const IItemParamsNode* damageEffectParams = actorParams ? actorParams->GetChild("DamageEffectParams") : 0;

	if (damageEffectParams)
	{
		int numChildren = damageEffectParams->GetChildCount();
		int allowSerialise = 1;

		damageEffectParams->GetAttribute("allowSerialise", allowSerialise);
		m_allowSerialise = allowSerialise ? true : false;

		CRY_ASSERT_MESSAGE(numChildren <= MAX_NUM_DAMAGE_EFFECTS, "Too many damage effects found. Increase the MAX_NUM_DAMAGE_EFFECTS and size of activeEffects and effectsResetSwitch");

		for (int i = 0; i < numChildren; i++)
		{
			const IItemParamsNode* child = damageEffectParams->GetChild(i);
			const IItemParamsNode* effect = child->GetChild(0);

			const char* hittype = child->GetAttribute("hittype");
			const char* name = effect->GetName();

			m_associatedHitType[i] = pGameRules->GetHitTypeId(hittype);

			child->GetAttribute("minDamage", m_minDamage[i]);	
			
			uint64 hashcode = CreateHash(name);

			if (hashcode == CKVoltEffect::s_hashId)
			{
				m_effectList[i] = new CKVoltEffect();
			}
			else if (hashcode == CTinnitusEffect::s_hashId)
			{
				m_effectList[i] = new CTinnitusEffect();
			}
			else if (hashcode == CEntityTimerEffect::s_hashId)
			{
				m_effectList[i] = new CEntityTimerEffect();
			}
			else
			{
				GameWarning("INVALID DAMAGE EFFECT PARSED");
				m_associatedHitType[i] = -1;
			}
			
			if(m_effectList[i])
			{
				m_effectList[i]->Init(actor, effect);
			}
		}
	}
}
Exemple #7
0
protected func Initialize() {
	hOldContents = CreateHash();
}
int main () {
	hash_table hash_array;
	hash_table* hash_info = &hash_array;
	hash_info->size = 256;
	CreateHash(hash_info);
	struct timespec start, stop;
    	double worktime;

// test AddElement
	unsigned long j;
	char tmp[LENGTH] = {0};

	if (clock_gettime( CLOCK_REALTIME, &start) == -1) {
     		perror ("clock gettime");
		return -1;
     	}
   	
	for ( j = 0; j < 10000; ++j ) {
		AddElement(GenerateRandomString(tmp), hash_info);
	}

    	if (clock_gettime( CLOCK_REALTIME, &stop) == -1) {
      		perror ("clock gettime");
		return -1;
      	}

    	worktime = ((( stop.tv_sec - start.tv_sec )*1e9 + ( stop.tv_nsec - start.tv_nsec ))*1e-9)/10000;
    	printf ("%.10f sec for AddElement cycle \n", worktime);

// test SearchElement
	if (clock_gettime( CLOCK_REALTIME, &start) == -1) {
     		perror ("clock gettime");
		return -1;
     	}
   	
	for ( j = 0; j < 10000; ++j ) {
		SearchElement(GenerateRandomString(tmp), hash_info);
	}

    	if (clock_gettime( CLOCK_REALTIME, &stop) == -1) {
      		perror( "clock gettime" );
		return -1;
      	}

    	worktime = ((( stop.tv_sec - start.tv_sec )*1e9 + ( stop.tv_nsec - start.tv_nsec ))*1e-9)/10000;
    	printf("%.10f sec for SearchElement cycle \n", worktime);

// test Remove 
	if (clock_gettime( CLOCK_REALTIME, &start) == -1) {
     		perror( "clock gettime" );
		return -1;
     	}
   	int k;
	for ( j = 0; j < 10000; ++j ) {
		k = Remove(GenerateRandomString(tmp), hash_info);
	}

    	if (clock_gettime( CLOCK_REALTIME, &stop) == -1) {
      		perror( "clock gettime" );
		return -1;
      	}

    	worktime = ((( stop.tv_sec - start.tv_sec )*1e9 + ( stop.tv_nsec - start.tv_nsec ))*1e-9)/10000;
    	printf ("%.10f sec for Remove cycle \n", worktime);


// test CleanMemory 	
	if (clock_gettime( CLOCK_REALTIME, &start) == -1) {
     		perror ("clock gettime");
		return -1;
     	}
   	
	for ( j = 0; j < 10000; ++j ) {
		hash_table hash_array;
		hash_table* hash_info = &hash_array;
		hash_info->size = 256;
		CreateHash(hash_info);
		CleanMemory(hash_info);
	}
	
	if (clock_gettime( CLOCK_REALTIME, &stop) == -1) {
      		perror( "clock gettime" );
		return -1;
      	}

    	worktime = ((( stop.tv_sec - start.tv_sec )*1e9 + ( stop.tv_nsec - start.tv_nsec ))*1e-9)/10000;
    	printf ("%.10f sec for CreateHash and CleanMemory cycle\n", worktime);	


	return 0;
}