Exemplo n.º 1
0
hash_token_t *uq_tokenize_to_hash(const char *str, const char *delimiters) {

	unsigned int hash;
	hash_token_t *s, *table = NULL;
	char *tok;
	char tmp[strlen(str) + 1];
	strcpy(tmp, str);

	tok = strtok(tmp, delimiters);

	while(tok != NULL) {

		hash = str_hash(tok);

		HASH_FIND_INT(table, &hash, s);

		if(s == NULL) {

			s = malloc(sizeof(hash_token_t));
			s->key = str_hash(tok);
			s->value = strdup(tok);
			HASH_ADD_INT(table, key, s);

		}

		tok = strtok(NULL, delimiters);

	}

	return (table);

}
Exemplo n.º 2
0
/**
 * @brief admin_img the function to deal with admin reqeust for disk mode
 *
 * @param req the evhtp request
 * @param md5 the file md5
 * @param t admin type
 *
 * @return 1 for OK, 2 for 404 not found and -1 for fail
 */
int admin_img(evhtp_request_t *req, thr_arg_t *thr_arg, char *md5, int t)
{
    int result = -1;

    LOG_PRINT(LOG_DEBUG, "amdin_img() start processing admin request...");
    char whole_path[512];
    int lvl1 = str_hash(md5);
    int lvl2 = str_hash(md5 + 3);
    snprintf(whole_path, 512, "%s/%d/%d/%s", settings.img_path, lvl1, lvl2, md5);
    LOG_PRINT(LOG_DEBUG, "whole_path: %s", whole_path);

    if(is_dir(whole_path) == -1)
    {
        LOG_PRINT(LOG_DEBUG, "path: %s is not exist!", whole_path);
        return 2;
    }

    if(t == 1)
    {
        if(delete_file(whole_path) != -1)
        {
            result = 1;
            evbuffer_add_printf(req->buffer_out, 
                "<html><body><h1>Admin Command Successful!</h1> \
                <p>MD5: %s</p> \
                <p>Command Type: %d</p> \
                </body></html>",
                md5, t);
            evhtp_headers_add_header(req->headers_out, evhtp_header_new("Content-Type", "text/html", 0, 0));
        }
    }
Exemplo n.º 3
0
Arquivo: arrays.c Projeto: Vuzi/vuziks
return_code arrays_array(Object* o, Linked_list *args, Variable* eval_value, int as_constructor) {

    (void)o;
    (void)args;

    if(!as_constructor) {
        err_add(E_ERROR, OP_IMPOSSIBLE, "Can't use this built-in function (arrays.array) as a function");
        return RC_ERROR;
    }

    // Nouvel objet array
    eval_value->type = T_OBJECT;
    eval_value->value.v_obj = var_new_object(NULL);

    // Nom d'objet : array
    eval_value->value.v_obj->name = "array";
    eval_value->value.v_obj->name_h = ARRAY_HASH;

    // Array en lui même
    Array* ar = xcalloc(1, sizeof(Array));

    eval_value->value.v_obj->data = (void*)ar;

    // Initialisation de l'array
    array_init(ar);

    // Fonction des strings

    Variable *v = var_new("add", str_hash("add"), T_FUNCTION_BUILTIN);
    v->value.v_func_builtin = arrays_array_add;
    v->container = &eval_value->value.v_obj->ec;
    v->container->object = eval_value->value.v_obj;

    linked_list_push(&(eval_value->value.v_obj->ec.variables), LLT_VARIABLE, (void*)v);

    v = var_new("get", str_hash("get"), T_FUNCTION_BUILTIN);
    v->value.v_func_builtin = arrays_array_get;
    v->container = &eval_value->value.v_obj->ec;
    v->container->object = eval_value->value.v_obj;

    linked_list_push(&(eval_value->value.v_obj->ec.variables), LLT_VARIABLE, (void*)v);

    v = var_new("pop", str_hash("pop"), T_FUNCTION_BUILTIN);
    v->value.v_func_builtin = arrays_array_pop;
    v->container = &eval_value->value.v_obj->ec;
    v->container->object = eval_value->value.v_obj;

    linked_list_push(&(eval_value->value.v_obj->ec.variables), LLT_VARIABLE, (void*)v);

    v = var_new("length", str_hash("length"), T_FUNCTION_BUILTIN);
    v->value.v_func_builtin = arrays_array_length;
    v->container = &eval_value->value.v_obj->ec;
    v->container->object = eval_value->value.v_obj;

    linked_list_push(&(eval_value->value.v_obj->ec.variables), LLT_VARIABLE, (void*)v);

    return RC_OK;
}
Exemplo n.º 4
0
std::size_t UIntPolyFlint::__hash__() const
{
    std::hash<std::string> str_hash;
    std::size_t seed = UINTPOLYFLINT;

    seed += str_hash(var_->get_name());
    hash_combine(seed, str_hash(poly_.to_string()));
    return seed;
}
Exemplo n.º 5
0
size_t hash1( const std::string& s )
{
        std::string ns = s;
        makelowercase(ns);
        std::hash< std::string > str_hash;
        return str_hash(ns);   
}
Exemplo n.º 6
0
int Shash_del(T *hash, char *key)
{
    int index, flag = 0;
    NODE_T **p, *q;
    BUCKET_T *bucket;

    assert(key);
    assert(hash);
    index  = MOD(str_hash(key), hash->len);
    bucket = &hash->buckets[index];

    if (!bucket->list)
        return -1;

    p = &bucket->list;
    do {
        q = (*p)->next;
        if (str_equal((*p)->key, key)) {
            FREE(*p);
            *p   = q;
            flag = 1;
            break;
        }
        p = &(*p)->next;
    } while (q);
    return flag? 0 : -1;
}
Exemplo n.º 7
0
int Shash_insert(T *hash, char *key, void *value)
{
    int index;
    NODE_T *real, *p;
    BUCKET_T *bucket;

    assert(key);
    assert(hash);
    if (!ALLOC(real, hash->size + sizeof(NODE_T))) {
        return -1;
    }
    if (!ALLOC(real->key, strlen(key) + 1)) {
        FREE(real);
        return -1;
    }
    strcpy(real->key, key);
    memcpy((char*)real + sizeof(NODE_T), value, hash->size);

    index = MOD(str_hash(key), hash->len);
    bucket = &hash->buckets[index];

    p = bucket->list;
    real->next  = p;
    bucket->list = real;
    return 0;
}
Exemplo n.º 8
0
void *sumproduct_sumproductalgorithm(void *arglist)
{
	void *argptr, *argptr2, *xptr;
	hgph *graph;
	nodes *root;
	char *userinputroot;
	//Get previous hgph struct
	if(dynamic_getarg(arglist,"hgph",&argptr)=='f') return NULL;
	if(!invalidptr(E,argptr)) graph=(hgph *) argptr;

	//Get user input on root node
	if(dynamic_getarg(arglist,"root",&argptr2)=='f') return NULL;
	if(!invalidptr(E,argptr)) userinputroot=(char *) argptr2;

	//Get Xptr
	if(dynamic_getarg(arglist,"xclient",&xptr)=='f') return NULL;

	//Choose the root node
	root = find_node(str_hash(userinputroot),graph->nnodes,graph->nodelist);

	//Call the recursion step
	forwardtraverse(root,root,graph);
	backwardtraverse(root,root,graph);
	calculatemarginals(graph);

	printtoclient("Sum Product Successful", xptr);
	writeresultstofile(graph, xptr);

	//Return arglist
	arglist=NULL;
	dynamic_putarg("graph.hgph","hgph",(void *)graph,SZ,&arglist);

	return arglist;
}
Exemplo n.º 9
0
struct rtpp_node *rtpengine_hash_table_lookup(str callid, str viabranch, enum rtpe_operation op) {
	struct rtpengine_hash_entry *entry, *last_entry;
	unsigned int hash_index;
	struct rtpp_node *node;

	// sanity checks
	if (!rtpengine_hash_table_sanity_checks()) {
		LM_ERR("sanity checks failed\n");
		return 0;
	}

	// get first entry from entry list; jump over unused list head
	hash_index = str_hash(callid);
	entry = rtpengine_hash_table->row_entry_list[hash_index];
	last_entry = entry;

	// lock
	if (rtpengine_hash_table->row_locks[hash_index]) {
		lock_get(rtpengine_hash_table->row_locks[hash_index]);
	} else {
		LM_ERR("NULL rtpengine_hash_table->row_locks[%d]\n", hash_index);
		return 0;
	}

	while (entry) {
		// if callid found, return entry
		if ((str_equal(entry->callid, callid) && str_equal(entry->viabranch, viabranch)) ||
		    (str_equal(entry->callid, callid) && viabranch.len == 0 && op == OP_DELETE)) {
			node = entry->node;

			// unlock
			lock_release(rtpengine_hash_table->row_locks[hash_index]);

			return node;
		}

		// if expired entry discovered, delete it
		if (entry->tout < get_ticks()) {
			// set pointers; exclude entry
			last_entry->next = entry->next;

			// free current entry; entry points to unknown
			rtpengine_hash_table_free_entry(entry);

			// set pointers
			entry = last_entry;

			// update total
			rtpengine_hash_table->row_totals[hash_index]--;
		}

		last_entry = entry;
		entry = entry->next;
	}

	// unlock
	lock_release(rtpengine_hash_table->row_locks[hash_index]);

	return NULL;
}
Exemplo n.º 10
0
time_t xchat_list_time(xchat_plugin *ph, xchat_list *xlist, const char *name)
{
	unsigned int hash = str_hash(name);
	void* data;

	switch (xlist->type)
	{
	case LIST_NOTIFY:
		if (!xlist->notifyps)
			return (time_t)-1;
		switch (hash)
		{
		case 0x1ad6f:	// off
			return xlist->notifyps->lastoff;
		case 0xddf:	// on
			return xlist->notifyps->laston;
		case 0x35ce7b:	// seen
			return xlist->notifyps->lastseen;
		}
		break;

	case LIST_USERS:
		data = xlist->pos->data;
		switch (hash)
		{
		case 0xa9118c42:	// lasttalk
			return ((User*)data)->lasttalk;
		}
	}

	return (time_t)-1;
}
Exemplo n.º 11
0
HashValueEntry *refmap_get_strkey(RefMap *rm, const char *key_p, int key_size)
{
    HashValueEntry *ep, **epp;
    uint32_t hash;

    if (key_size < 0) {
        key_size = strlen(key_p);
    }
    hash = str_hash(key_p, key_size);

    // 一致しているか調べる
    epp = &rm->entry[hash & (rm->entry_num - 1)];
    ep = *epp;
    while (ep != NULL) {
        if (hash == ep->hash) {
            RefNode *key_type = Value_type(ep->key);
            if (key_type == fs->cls_str) {
                RefStr *rs = Value_vp(ep->key);
                if (rs->size == key_size && memcmp(rs->c, key_p, key_size) == 0) {
                    // 見つかった
                    return ep;
                }
            }
        }
        epp = &ep->next;
        ep = *epp;
    }
    // 見つからなかった
    return NULL;
}
Exemplo n.º 12
0
time_t
hexchat_list_time (hexchat_plugin *ph, hexchat_list *xlist, const char *name)
{
	guint32 hash = str_hash (name);
	gpointer data;

	switch (xlist->type)
	{
	case LIST_NOTIFY:
		if (!xlist->notifyps)
			return (time_t) -1;
		switch (hash)
		{
		case 0x1ad6f:	/* off */
			return xlist->notifyps->lastoff;
		case 0xddf:	/* on */
			return xlist->notifyps->laston;
		case 0x35ce7b:	/* seen */
			return xlist->notifyps->lastseen;
		}
		break;

	case LIST_USERS:
		data = xlist->pos->data;
		switch (hash)
		{
		case 0xa9118c42:	/* lasttalk */
			return ((struct User *)data)->lasttalk;
		}
	}

	return (time_t) -1;
}
Exemplo n.º 13
0
void ProfilerTest::test_code_point() {
    CodePoint cp = CODE_POINT("my_tag");    unsigned int line_save = __LINE__;
    EXPECT_EQ("my_tag", cp.tag_);
    EXPECT_EQ( str_hash("my_tag", PROFILER_HASH_DEFAULT), cp.hash_);
    EXPECT_EQ( line_save, cp.line_ );
    //EXPECT_EQ(string("(profiler_test.cpp, xxx(), 130)"), string(CODE_POINT) );
}
Exemplo n.º 14
0
TEST(Profiler, CodePoint) {
    CodePoint cp = CODE_POINT("my_tag");    unsigned int line_save = __LINE__;
    EXPECT_EQ("my_tag", cp.tag_);
    EXPECT_EQ( str_hash("my_tag"), cp.hash_);
    EXPECT_EQ( line_save, cp.line_ );
    //EXPECT_EQ(string("(profiler_test.cpp, xxx(), 130)"), string(CODE_POINT) );
}
Exemplo n.º 15
0
static SSL_CTX *hash_table_lookup(char *key_file, time_t *pmtime)
{
   int level, split;
   uint32_t hash = str_hash(key_file);
   size_t bucket;
   struct bucket *el;

   split = ht.split;
   level = ht.level;

   bucket = hash & ((1 << level) - 1);
   if (bucket < split)
      bucket = hash & ((1 << (level + 1)) - 1);

   el = ht.buckets[bucket];
   while (el != NULL) {
      if (el->hash == hash && strcmp(el->key_file, key_file) == 0) {
	 *pmtime = el->mtime;
	 return el->ssl_ctx;
      }
      el = el->next;
   }

   return NULL;
}
Exemplo n.º 16
0
//-----------------------------------------------------------------------------
void str_nappend(Str *dst, char *val, int n)
{
	dst->val = realloc(dst->val, dst->len + n + 1);
	strncpy(dst->val + dst->len, val, n);
	dst->len = dst->len + n;
	dst->val[dst->len] = 0;
	dst->hash = str_hash(dst->val, dst->len);
}
Exemplo n.º 17
0
//-----------------------------------------------------------------------------
inline void str_nset(Str *str, char *val, int n)
{
	str->len = n;
	str->val = realloc(str->val, str->len + 1);
	strncpy(str->val, val, n);
	str->val[str->len] = 0;
	str->hash = str_hash(str->val, str->len);
}
Exemplo n.º 18
0
std::size_t URatPSeriesFlint::__hash__() const {
    std::hash<std::string> str_hash;
    std::size_t seed = URATPSERIESFLINT;
    hash_combine(seed, var_);
    hash_combine(seed, degree_);
    hash_combine(seed, str_hash(p_.to_string()));
    return seed;
}
Exemplo n.º 19
0
UtilString *util_str_create(char *buff)
{
	UtilString *ret = malloc(sizeof(UtilString));
	ret->hash = str_hash(buff);
	ret->len = strlen(buff);
	ret->buff = buff;
	return ret;
}
Exemplo n.º 20
0
unsigned int DiskMultiMap::getHash(std::string s)
{
    std::hash<std::string> str_hash;
    
    headerNode head;
    m_bf.read(head, 0);
    
    return str_hash(s) % head.m_numBuckets;
}
Exemplo n.º 21
0
void str_dict_delete(struct dict * h, char * key) {
  if (str_lookup(h, key)) {
    // Key has to exist to be deleted
    struct dict_entry * entry = NULL, * temp = NULL;
    if ((entry = h -> hashtab[str_hash(h, key)]) && (h -> hashtab[str_hash(h, key)]) -> key == key) {
      // First element in the hashtab
      h -> hashtab[str_hash(h, key)] = entry -> next;
      return;
    }
    for (entry = (h -> hashtab[str_hash(h, key)]); entry -> next != NULL; entry = entry -> next) {
      if (entry -> next -> key == key) {
        temp = entry -> next;
        // Found the entry: delete it
        entry -> next = temp -> next;
      }
    }
  }
}
Exemplo n.º 22
0
struct dict_entry * str_lookup(struct dict * h, char * key) {
  // Find the str_dict_entry element corresponding to a key
  // Return NULL if key not present
  struct dict_entry * entry ;
  for (entry = (h -> hashtab[str_hash(h, key)]); entry != NULL; entry = entry -> next)
    if (! strcmp(key, entry -> key))
      return entry; // Found the entry with key: key
  return NULL; // No entries found
}
Exemplo n.º 23
0
Arquivo: arrays.c Projeto: Vuzi/vuziks
// Initialisation de l'objet built-in string
Object* arrays_init(Exec_context* ec_obj) {
    // Création de l'objet
    Object* o = var_new_object(NULL);

    (void)ec_obj;

    // Définition du type
    o->name = "arrays";
    o->name_h = str_hash(o->name);

    // Ajout des fonctions
    Variable* v = var_new("array", str_hash("array"), T_FUNCTION_BUILTIN);
    v->value.v_func_builtin = arrays_array;
    v->container = &o->ec; v->container->object = o;
    linked_list_push(&(o->ec.variables), LLT_VARIABLE, (void*)v);

    return o;
}
Exemplo n.º 24
0
void Response::setUID()
{
	std::istringstream convert;
	std::hash<std::string> str_hash;
	std::time_t timeNow = std::time(NULL);
	convert >> timeNow;
	content += convert.str();
	uid = str_hash(content);
}
Exemplo n.º 25
0
Propdef
dbpriv_new_propdef(const char *name)
{
    Propdef newprop;

    newprop.name = str_ref(name);
    newprop.hash = str_hash(name);
    return newprop;
}
Exemplo n.º 26
0
std::size_t URatPolyFlint::__hash__() const
{
    std::hash<std::string> str_hash;
    std::size_t seed = URATPOLYFLINT;

    seed += var_->hash();
    hash_combine(seed, str_hash(poly_.to_string()));
    return seed;
}
Exemplo n.º 27
0
TEST(Profiler, str_hash) {
    EXPECT_EQ(0, str_hash(""));
    EXPECT_EQ(65, str_hash("A"));
    EXPECT_EQ(6597, str_hash(" A"));

    srand ( time(NULL) );
    char a[16];
    char b[16];

// random test for hash collision
    unsigned int n_pairs=100;
    for(unsigned int i=0; i<n_pairs; i++) {
        random_string(a);
        random_string(b);
        if (string(a) != string(b) )
            EXPECT_NE( str_hash(a) , str_hash(b) );
    }
}
Exemplo n.º 28
0
void ProfilerTest::test_str_hash() {
    EXPECT_EQ(0, str_hash("", PROFILER_HASH_DEFAULT));
    EXPECT_EQ(65, str_hash("A", PROFILER_HASH_DEFAULT));
    EXPECT_EQ(6597, str_hash(" A", PROFILER_HASH_DEFAULT));

    srand ( time(NULL) );
    char a[16];
    char b[16];

    // random test for hash collision
    unsigned int n_pairs=100;
    for(unsigned int i=0; i<n_pairs; i++) {
        random_string(a);
        random_string(b);
        if (string(a) != string(b) )
            EXPECT_NE( str_hash(a, PROFILER_HASH_DEFAULT) , str_hash(b, PROFILER_HASH_DEFAULT) );
    }
}
Exemplo n.º 29
0
String sb_hash(const String& str)
{
  // Get the filename hash
  std::hash<String> str_hash;
  std::size_t hash = str_hash(str);
  
  // Convert the hash to a string :(
  std::ostringstream ss;
  ss << hash;
  return ss.str();
}
Exemplo n.º 30
0
MDNode *SimpleHash_get_node(SimpleHash **hash, const char *name)
{
    uint32_t ihash = str_hash(name);
    SimpleHash *h = hash[ihash];
    for (; h != NULL; h = h->next) {
        if (ihash == h->hash && strcmp(name, h->name) == 0) {
            return h->node;
        }
    }
    return NULL;
}