Exemple #1
0
CommandContainer commandContainerCreate(){
	CommandContainerInternal* m=(CommandContainerInternal*)memoryAlloc(sizeof(CommandContainerInternal));
	m->versionMap=hashmapCreate(SMALL_CONTAINER_SIZE);
        m->versions=linkedListCreate();
        m->atomicCommands=linkedListCreate();
        m->lock=lockCreate();
	return m;
}
void main(int argc, char* argv[])
{
  Node * head = linkedListCreate(testHashMapOneValue);
  linkedListAdd(head, testHashMapSixValues);
  linkedListAdd(head, testHashMapTwelveValues);
  linkedListAdd(head, testHashMapGetMissingKey);
  linkedListAdd(head, testHashMapRemoveSixValues);
  Node * testNode = head;    
  while (testNode != NULL)
  {
    ((void (*)(void))testNode->data)();
	printf("\n");
    testNode = testNode->next;
  }
  
  testNode = head;
  while(testNode != NULL)
  {
    testNode = linkedListRemove(head, testNode);
  }

  printf("%d asserts successful.\n", assertsGetTotal());
  if (assertsGetFailures() > 0)
  {
    printf("%d asserts failed.\n", assertsGetFailures());
  }
  else
  {
    printf("All tests successful.\n");
  }
   
  return;
}
Exemple #3
0
Properties propertiesCreate(char *filePath) {
    PropertiesInternal *m = (PropertiesInternal *) memoryAlloc(sizeof(PropertiesInternal));
    m->map = hashmapCreate(SMALL_CONTAINER_SIZE);
    FILE *fp;
    long len;
    char *buf;
    fp = fopen(filePath, "rt");
    if (fp == NULL) {
        printf("couldn't open the properties file");
    };
    fseek(fp, 0, SEEK_END);            //go to end
    len = ftell(fp);                    //get position at end (length)
    fseek(fp, 0, SEEK_SET);            //go to beg.
    buf = (char *) memoryAlloc(len + 1);        //malloc buffer
    long result = fread(buf, (size_t) (len + 1), 1, fp);            //read into buffer
    if (result < 0) {
        printf("Fail to read properties file .");
    }
    fclose(fp);
    buf[len] = 0;
    char *key;
    char *value;
    const char newLineDelimiter[] = "\n";
    const char spaseDelimiter[] = "=";
    char *token;
    token = strtok(buf, newLineDelimiter);
    LinkedList linkedList = linkedListCreate();
    while (token != NULL) {
        linkedListAddFirst(linkedList, token);
        token = strtok(NULL, newLineDelimiter);
    }
    while (linkedListSize(linkedList) > 0) {
        char *token = (char *) linkedListRemoveFirst(linkedList);
        key = strtok(token, spaseDelimiter);
        value = strtok(NULL, spaseDelimiter);
        unsigned int keyId = stringTransformToInt(key, strlen(key));
        hashmapPut(m->map, keyId, value);
    }
    linkedListFree(linkedList);

    return m;
}
Exemple #4
0
int main(int argc, char* argv[])
{
	#ifdef MEMORY_TEST_INCLUDED
	// Memory used BEFORE creating LinkedList
	long m1 = getMemoryUsage();
	#endif

	if (argc != 2)
	{
		printf("Usage: %s <number of elements to add>\n", argv[0]);
		return 1;
	}

	struct LinkedList* list = linkedListCreate(); 
	int numElements = atoi(argv[1]);
	for (int i = 1 ; i <= numElements; i++)
	{
		linkedListAddBack(list, (TYPE)i);
		linkedListRemoveFront(list);
	}

	linkedListAddBack(list, (TYPE)10);
        linkedListPrint(list);

	#ifdef MEMORY_TEST_INCLUDED
	// Memory used AFTER creating LinkedList
	long m2 = getMemoryUsage();
	printf("Memory used by LinkedList: %ld KB \n", m2 - m1);
	#endif

	double t1 = getMilliseconds(); // Time before contains()
	for (int i = 0; i < numElements; i++)
	{
		linkedListContains(list, i);
	}
	double t2 = getMilliseconds(); // Time after contains()
	printf("Time for running contains() on %d elements: %g ms\n", numElements, t2 - t1);

	linkedListDestroy(list);

	return 0;
}