Ejemplo n.º 1
0
Archivo: Hash.cpp Proyecto: tinysk/ajs
    int32_t HashTable::insert(st_data_t key, st_data_t value)
    {
		st_index_t hashVal, binPos;
        HashEntry* entry;

		FIND_ENTRY(entry, key, hashVal, binPos);
        if(entry == NULL)
            ADD_DIRECT(key, value, hashVal, binPos);
        else
            entry->record = value;            

        return 1; 
    }
Ejemplo n.º 2
0
int
st_lookup(st_table *table, const char *key, const void **value)
{
    unsigned int hash_val, bin_pos;
    register st_table_entry *ptr;

    hash_val = do_hash(key, table);
    FIND_ENTRY(table, ptr, hash_val, bin_pos);

    if (ptr == 0) {
	return 0;
    }
    else {
	if (value != 0)  *value = ptr->record;
	return 1;
    }
}
Ejemplo n.º 3
0
int
cocoa_st_lookup(cocoa_st_table *table, cocoa_st_data_t key, cocoa_st_data_t *value)
{
    unsigned int hash_val, bin_pos;
    register cocoa_st_table_entry *ptr;

    hash_val = do_hash(key, table);
    FIND_ENTRY(table, ptr, hash_val, bin_pos);

    if (ptr == 0) {
        return 0;
    }
    else {
        if (value != 0)  *value = ptr->record;
        return 1;
    }
}
Ejemplo n.º 4
0
int
st_insert(st_table *table, const char *key, const void *value)
{
    unsigned int hash_val, bin_pos;
    register st_table_entry *ptr;

    hash_val = do_hash(key, table);
    FIND_ENTRY(table, ptr, hash_val, bin_pos);

    if (ptr == 0) {
	ADD_DIRECT(table, key, value, hash_val, bin_pos);
	return 0;
    }
    else {
	ptr->record = value;
	return 1;
    }
}
Ejemplo n.º 5
0
int
cocoa_st_insert(cocoa_st_table *table, cocoa_st_data_t key, cocoa_st_data_t value)
{
    unsigned int hash_val, bin_pos;
    register cocoa_st_table_entry *ptr;

    hash_val = do_hash(key, table);
    FIND_ENTRY(table, ptr, hash_val, bin_pos);

    if (ptr == 0) {
        ADD_DIRECT(table, key, value, hash_val, bin_pos);
        return 0;
    }
    else {
        ptr->record = value;
        return 1;
    }
}
Ejemplo n.º 6
0
int
st_find(st_table *table, char *key, char ***slot)
{
    int hash_val;
    st_table_entry *ptr, **last;

    hash_val = do_hash(key, table);

    FIND_ENTRY(table, hash_val, key, ptr, last);

    if (ptr == NULL) {
	return 0;
    } else {
	if (slot != NULL) {
	    *slot = &ptr->record;
	}
	return 1;
    }
}
Ejemplo n.º 7
0
int
st_lookup_int(st_table *table, char *key, int *value)
{
    int hash_val;
    st_table_entry *ptr, **last;

    hash_val = do_hash(key, table);

    FIND_ENTRY(table, hash_val, key, ptr, last);
    
    if (ptr == NULL) {
	return 0;
    } else {
	if (value != 0) {
	    *value = (long) ptr->record;
	}
	return 1;
    }
}
Ejemplo n.º 8
0
int
 st__lookup( st__table *table, const char *key, char **value)
{
    int hash_val;
    st__table_entry *ptr, **last;

    hash_val = do_hash(key, table);

    FIND_ENTRY(table, hash_val, key, ptr, last);
    
    if (ptr == NULL) {
    return 0;
    } else {
    if (value != NULL) {
        *value = ptr->record; 
    }
    return 1;
    }
}
Ejemplo n.º 9
0
int
st_delete_int(st_table *table, long *keyp, char **value)
{
    int hash_val;
    char *key = (char *) *keyp;
    st_table_entry *ptr, **last;

    hash_val = do_hash(key, table);

    FIND_ENTRY(table, hash_val, key, ptr ,last);

    if (ptr == NULL) {
        return 0;
    }

    *last = ptr->next;
    if (value != NULL) *value = ptr->record;
    *keyp = (long) ptr->key;
    ABC_FREE(ptr);
    table->num_entries--;
    return 1;
}
Ejemplo n.º 10
0
int
st_insert(register st_table *table, register st_data_t key, st_data_t value)
{
    unsigned int hash_val, bin_pos;
    register st_table_entry *ptr;

    if (table->entries_packed) {
        int i;
        for (i = 0; i < table->num_entries; i++) {
            if ((st_data_t)table->bins[i*2] == key) {
                table->bins[i*2+1] = (struct st_table_entry*)value;
                return 1;
            }
        }
        if ((table->num_entries+1) * 2 <= table->num_bins && table->num_entries+1 <= MAX_PACKED_NUMHASH) {
            i = table->num_entries++;
            table->bins[i*2] = (struct st_table_entry*)key;
            table->bins[i*2+1] = (struct st_table_entry*)value;
            return 0;
        }
        else {
            unpack_entries(table);
        }
    }

    hash_val = do_hash(key, table);
    FIND_ENTRY(table, ptr, hash_val, bin_pos);

    if (ptr == 0) {
	ADD_DIRECT(table, key, value, hash_val, bin_pos);
	return 0;
    }
    else {
	ptr->record = value;
	return 1;
    }
}
Ejemplo n.º 11
0
int
call_function(ZARRAYP libID, const char *funcname, ZARRAYP argtypes, ZARRAYP args, ZARRAYP retval)
{
  /* Last value in argtypes and ffi_types is the type of "funcname" return value */ 
  int maxargs = argtypes->len - 1, nargs;
  ffi_cif cif;
  ffi_type *ffi_types[maxargs + 1]; 
  void *ffi_values[maxargs];

  int i, j;
  size_t fullsize = 0, size = 0;
  storage mem;
  init_storage(&mem);


  for (i = 0, j = 0; i < maxargs + 1; ++j, ++i) {
    size = get_size(argtypes->data[i]);
    ffi_types[j] = get_ffi_type(argtypes, &i, &mem);
    if (!ffi_types[j]) {
      return ZF_FAILURE;
    }
    if (ffi_types[j] == &ffi_type_void && i != maxargs) {
      logger("CNA_VOID type may be used only for return value\n");
      return ZF_FAILURE;
    }
    if (size == 0 && ffi_types[j] != &ffi_type_void && i != maxargs) {
      size = *((size_t *)(args->data + fullsize));
      fullsize += sizeof(size_t);
    }
    if (i != maxargs) {
      ffi_values[j] = args->data + fullsize;
    }
    fullsize += size;
  }

  retval->len = size;
  nargs = j - 1;

  if (fullsize != args->len + retval->len) {
    logger("Wrong size of ZARRAYP\n\tfullsize: %u\tZARRAYP args: %u\tretsize: %u\n", fullsize, args->len, retval->len);
    return ZF_FAILURE;
  }

  void *handle;
  if (assign_ZARRAYP_to_pointer(&handle, libID)) {
    return ZF_FAILURE;
  }

  if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, nargs, ffi_types[nargs], ffi_types) != FFI_OK) {
    logger("ffi_prep_cif() failed\n");
    return ZF_FAILURE;
  }
  
  if (retval->len == 0 && ffi_types[nargs] != &ffi_type_void) {
    retval->len = cif.arg_types[nargs]->size;
  }

  void *funcpointer = FIND_ENTRY(handle, funcname);

  if (!funcpointer) {
    logger("FIND_ENTRY() failed\n\thandle:%d\tfuncname:%s\n", handle, funcname);
    return ZF_FAILURE;
  }

  ffi_call(&cif, funcpointer, retval->data, ffi_values);

  /* TODO: handle error */

  free_storage(&mem);

  return ZF_SUCCESS;
}