static void
remove_private_vect(ClipMachine * ClipMachineMemory, int num, void *vect)
{
   long *lp = (long *) vect;

   for (; num > 0; --num, ++lp)
   {
      long hash = GETLONG(lp);

      VarEntry *vp = (VarEntry *) HashTable_fetch(ClipMachineMemory->privates, hash);

      if (!vp)
	 continue;
      if (vp->VarEntry_next_of_VarEntry)
      {
	 HashTable_remove(ClipMachineMemory->privates, hash);
	 HashTable_store(ClipMachineMemory->privates, vp->VarEntry_next_of_VarEntry, hash);
	 vp->VarEntry_next_of_VarEntry = 0;
      }
      else
      {
	 HashTable_remove(ClipMachineMemory->privates, hash);
      }
      delete_VarEntry(ClipMachineMemory, vp);
   }
}
示例#2
0
文件: main.c 项目: tobiajo/advanced-c
int main(int argc, char *argv[]) {

	HashTable ht = newHashTable(65535);
	
	HashTable_put(ht, "1", "two");
	HashTable_put(ht, "2", "three");
	HashTable_put(ht, "3", "five");
	HashTable_put(ht, "4", "seven");
	HashTable_put(ht, "5", "eleven");
	HashTable_put(ht, "6", "thirteen");
	HashTable_put(ht, "7", "seventeen");

	HashTable_remove(ht, "1");
	HashTable_remove(ht, "2");
	HashTable_remove(ht, "6");
	HashTable_remove(ht, "7");

	HashTable_put(ht, "3", "not allowed");

	printf("%s\n", HashTable_get(ht, "1"));
	printf("%s\n", HashTable_get(ht, "2"));
	printf("%s\n", HashTable_get(ht, "3"));
	printf("%s\n", HashTable_get(ht, "4"));
	printf("%s\n", HashTable_get(ht, "5"));
	printf("%s\n", HashTable_get(ht, "6"));
	printf("%s\n", HashTable_get(ht, "7"));

	printf("size: %d\n", HashTable_size(ht));	

	freeHashTable(&ht);

	return 0;
}
示例#3
0
static VarEntry *
add_private(ClipMachine * ClipMachineMemory, long hash)
{
    long *p;

    VarEntry *vp, *np;

    ClipFrame *fp;

    if (ClipMachineMemory->inMacro)
        fp = ClipMachineMemory->inMacro;
    else
        fp = ClipMachineMemory->fp;

    if (fp)
    {
        p = fp->privates_of_ClipFrame;
        if (p)
        {
            int n;

            long c;

            for (n = *p, p++; n >= 0; n--, p++)
                if (hash == GETLONG(p))
                {
                    vp = (VarEntry *) HashTable_fetch(ClipMachineMemory->privates, hash);
                    if (vp)
                        return vp;
                }
            p = fp->privates_of_ClipFrame;
            c = GETLONG(p);
            p = (long *) realloc(p, (c + 2) * sizeof(long));

            SETLONG(p, c + 1);
            SETLONG(p + c + 1, hash);
            fp->privates_of_ClipFrame = p;
        }
        else
        {
            p = fp->privates_of_ClipFrame = (long *) malloc(sizeof(long) * 2);

            SETLONG(p, 1);
            SETLONG(p + 1, hash);
        }
    }

    vp = (VarEntry *) HashTable_fetch(ClipMachineMemory->privates, hash);
    np = new_VarEntry(hash);
    if (!vp)
        HashTable_insert(ClipMachineMemory->privates, np, hash);
    else
    {
        np->VarEntry_next_of_VarEntry = vp;
        HashTable_remove(ClipMachineMemory->privates, hash);
        HashTable_store(ClipMachineMemory->privates, np, hash);
    }
    return np;
}
int vnet_peer_del(VarpAddr *addr){
    int ret = 0;
    unsigned long flags;

    vnet_peer_write_lock(flags);
    ret = HashTable_remove(vnet_peer_table, addr);
    vnet_peer_write_unlock(flags);
    return ret;
}