예제 #1
0
int
HashTableInsert(HashTable *h, void *k, void *v)
{
    /* This method allows duplicate keys - but they shouldn't be used */
    unsigned int index;
    struct entry *e;

    HashTableRemove(h,k); // get rid of key, if it already exists!
    if (++(h->entrycount) > h->loadlimit)
    {
        /* Ignore the return value. If expand fails, we should
         * still try cramming just this value into the existing table
         * -- we may not have memory for a larger table, but one more
         * element may be ok. Next time we insert, we'll try expanding again.*/
        HashTableExpand(h);
    }
    e = (struct entry *)MALLOC(sizeof(struct entry));
    if (NULL == e) { --(h->entrycount); return 0; } /*oom*/
    e->h = hash(h,k);
    index = indexFor(h->tablelength,e->h);
    e->k = k;
    e->v = v;
    e->next = h->table[index];
    h->table[index] = e;
    return -1;
}
예제 #2
0
static int HashTableTestFull02 (void)
{
    int result = 0;
    HashTable *ht = HashTableInit(32, HashTableGenericHash, NULL, NULL);
    if (ht == NULL)
        goto end;

    int r = HashTableAdd(ht, "test", 4);
    if (r != 0)
        goto end;

    char *rp = HashTableLookup(ht, "test", 4);
    if (rp == NULL)
        goto end;

    r = HashTableRemove(ht, "test2", 5);
    if (r == 0)
        goto end;

    /* all is good! */
    result = 1;
end:
    if (ht != NULL) HashTableFree(ht);
    return result;
}
예제 #3
0
char *assign(char *name,char *value) {
  if (!symtab) shellinit();
  if (!value) {
    HashTableRemove(symtab,name);
  } else {
    HashTableInsert(symtab,name,value);
  }
  return value;
}
예제 #4
0
파일: configuration.c 프로젝트: ikeboy/mgba
void ConfigurationClearValue(struct Configuration* configuration, const char* section, const char* key) {
	struct Table* currentSection = &configuration->root;
	if (section) {
		currentSection = HashTableLookup(&configuration->sections, section);
		if (!currentSection) {
			return;
		}
	}
	HashTableRemove(currentSection, key);
}
예제 #5
0
static NTSTATUS
GnttabUnmapForeignPages(
    IN  PINTERFACE              Interface,
    IN  PHYSICAL_ADDRESS        Address
    )
{
    PXENBUS_GNTTAB_CONTEXT      Context = Interface->Context;
    ULONG                       PageIndex;
    PHYSICAL_ADDRESS            PageAddress;
    PXENBUS_GNTTAB_MAP_ENTRY    MapEntry;
    NTSTATUS                    status;

    status = HashTableLookup(Context->MapTable,
                             (ULONG_PTR)Address.QuadPart,
                             (PULONG_PTR)&MapEntry);
    if (!NT_SUCCESS(status))
        goto fail1;

    status = HashTableRemove(Context->MapTable,
                             (ULONG_PTR)Address.QuadPart);
    if (!NT_SUCCESS(status))
        goto fail2;

    PageAddress.QuadPart = Address.QuadPart;

    for (PageIndex = 0; PageIndex < MapEntry->NumberPages; PageIndex++) {
        status = GrantTableUnmapForeignPage(MapEntry->MapHandles[PageIndex],
                                            PageAddress);
        BUG_ON(!NT_SUCCESS(status));

        PageAddress.QuadPart += PAGE_SIZE;
    }

    FdoFreeIoSpace(Context->Fdo,
                   Address,
                   MapEntry->NumberPages * PAGE_SIZE);

    __GnttabFree(MapEntry);

    return STATUS_SUCCESS;

fail2:
    Error("fail2\n");

fail1:
    Error("fail1: (%08x)\n", status);

    return status;
}
예제 #6
0
파일: configuration.c 프로젝트: ikeboy/mgba
void ConfigurationSetValue(struct Configuration* configuration, const char* section, const char* key, const char* value) {
	struct Table* currentSection = &configuration->root;
	if (section) {
		currentSection = HashTableLookup(&configuration->sections, section);
		if (!currentSection) {
			if (value) {
				currentSection = malloc(sizeof(*currentSection));
				HashTableInit(currentSection, 0, _sectionDeinit);
				HashTableInsert(&configuration->sections, section, currentSection);
			} else {
				return;
			}
		}
	}
	if (value) {
		HashTableInsert(currentSection, key, strdup(value));
	} else {
		HashTableRemove(currentSection, key);
	}
}