当前位置: 首页>>代码示例>>C++>>正文


C++ dictionary_hash函数代码示例

本文整理汇总了C++中dictionary_hash函数的典型用法代码示例。如果您正苦于以下问题:C++ dictionary_hash函数的具体用法?C++ dictionary_hash怎么用?C++ dictionary_hash使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了dictionary_hash函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: dictionary_set

/*--------------------------------------------------------------------------*/
int dictionary_set(dictionary * d, char * key, char * val)
{
	int			i ;
	unsigned	hash ;

	if (d==NULL || key==NULL) return -1 ;

	/* Compute hash for this key */
	hash = dictionary_hash(key) ;
	/* Find if value is already in dictionary */
	if (d->n>0) {
		for (i=0 ; i<d->size ; i++) {
	    if (d->key[i]==NULL)
		continue ;
			if (hash==d->hash[i]) { /* Same hash value */
				if (!strcmp(key, d->key[i])) {	 /* Same key */
					/* Found a value: modify and return */
					if (d->val[i]!=NULL)
						free(d->val[i]);
		    d->val[i] = val ? xstrdup(val) : NULL ;
		    /* Value has been modified: return */
					return 0 ;
				}
			}
		}
	}
	/* Add a new value */
	/* See if dictionary needs to grow */
	if (d->n==d->size) {

		/* Reached maximum size: reallocate dictionary */
		d->val  = (char **)mem_double(d->val,  d->size * sizeof(char*)) ;
		d->key  = (char **)mem_double(d->key,  d->size * sizeof(char*)) ;
		d->hash = (unsigned int *)mem_double(d->hash, d->size * sizeof(unsigned)) ;
	if ((d->val==NULL) || (d->key==NULL) || (d->hash==NULL)) {
	    /* Cannot grow dictionary */
	    return -1 ;
	}
		/* Double size */
		d->size *= 2 ;
	}

    /* Insert key in the first empty slot */
    for (i=0 ; i<d->size ; i++) {
	if (d->key[i]==NULL) {
	    /* Add key here */
	    break ;
	}
    }
	/* Copy key */
	d->key[i]  = xstrdup(key);
    d->val[i]  = val ? xstrdup(val) : NULL ;
	d->hash[i] = hash;
	d->n ++ ;
	return 0 ;
}
开发者ID:jesseweigert,项目名称:waas,代码行数:57,代码来源:dictionary.cpp

示例2: dictionary_unset

/*--------------------------------------------------------------------------*/
void dictionary_unset(dictionary* d, const char* key)
{
    unsigned    hash ;
    size_t      i ;

    if (key == NULL)
    {
        return;
    }

    hash = dictionary_hash(key);

    for (i=0 ; i<(size_t)d->size ; i++)
    {
        if (d->key[i]==NULL)
        {
            continue ;
        }

        /* Compare hash */
        if (hash==d->hash[i])
        {
            /* Compare string, to avoid hash collisions */
            if (!strcmp(key, d->key[i]))
            {
                /* Found key */
                break ;
            }
        }
    }

    if (i>=(size_t)d->size)
        /* Key not found */
    {
        return ;
    }

    free(d->key[i]);
    d->key[i] = NULL ;

    if (d->val[i]!=NULL)
    {
        free(d->val[i]);
        d->val[i] = NULL ;
    }

    d->hash[i] = 0 ;
    d->n -- ;
    return ;
}
开发者ID:freeeyes,项目名称:PSS,代码行数:51,代码来源:dictionary.c

示例3: dictionary_getbufsize

int dictionary_getbufsize(dictionary * d, char * key)
{
	unsigned	hash ;
	int			i ;
	hash = dictionary_hash(key);
	for (i=0 ; i<d->size ; i++) {
        	if (d->key[i]==NULL)
            		continue ;
        	/* Compare hash */ 
		if (hash==d->hash[i]) {
            		/* Compare string, to avoid hash collisions */ 
            		if (!strcmp(key, d->key[i])) {
				return d->bufsize[i] ;
	    		}
		}
	}
	return 0 ;
}
开发者ID:UAF-SuperDARN-OPS,项目名称:SuperDARN_agc,代码行数:18,代码来源:dictionary.c

示例4: Assert

/*--------------------------------------------------------------------------*/
void dictionary_unset
    (LPDICTIONARY lpDict,       // Ptr to workspace dictionary
     LPWCHAR      lpwKey)

{
    UINT hash;
    int  i;

    Assert (lpDict NE NULL);
    Assert (lpwKey NE NULL);

    // Hash the key
    hash = dictionary_hash (lpwKey);

    for (i = 0; i < lpDict->size; i++)
    if (lpDict->key[i] NE NULL)
    {
        /* Compare hash */
        if (hash EQ lpDict->hash[i])
        {
            /* Compare string, to avoid hash collisions */
            if (!lstrcmpW (lpwKey, lpDict->key[i]))
                /* Found key */
                break;
        } // End IF
    } // End FOR/IF

    if (i >= lpDict->size)
        /* Key not found */
        return;

    // Free the key
    free (lpDict->key[i]); lpDict->key[i] = NULL;

    // Free values if they were allocated
    if (lpDict->val[i] NE NULL)
    {
        free (lpDict->val[i]);
        lpDict->val[i] = NULL;
    } // End IF

    lpDict->hash[i] = 0;
    lpDict->n--;
} // End dictionary_unset
开发者ID:PlanetAPL,项目名称:nars2000,代码行数:45,代码来源:dictionary.c

示例5: dictionary_get

/*--------------------------------------------------------------------------*/
static const char * dictionary_get(dictionary * d, const char * key, const char * def)
{
    unsigned    hash ;
    int         i ;

    hash = dictionary_hash(key);
    for (i=0 ; i<d->size ; i++) {
        if (d->key==NULL)
            continue ;
        /* Compare hash */
        if (hash==d->hash[i]) {
            /* Compare string, to avoid hash collisions */
            if (!strcmp(key, d->key[i])) {
                return d->val[i] ;
            }
        }
    }
    return def ;
}
开发者ID:ennorehling,项目名称:iniparser_old,代码行数:20,代码来源:iniparser.c

示例6: dictionary_hash

static t_hash_element *dictionary_get_element(t_dictionary *self, char *key) {
    unsigned int key_hash = dictionary_hash(key, strlen(key));
    int index = key_hash % self->table_max_size;

    t_hash_element *element = self->elements[index];

    if (element == NULL) {
        return NULL;
    }

    do {

        if (element->hashcode == key_hash) {
            return element;
        }

    } while ((element = element->next) != NULL);

    return NULL;
}
开发者ID:agustinmodugno,项目名称:TP-SO,代码行数:20,代码来源:dictionary.c

示例7: dictionary_unset

/*--------------------------------------------------------------------------*/
static void
dictionary_unset (dictionary * d, char * key)
{
    unsigned    hash;
    int         i;

    hash = dictionary_hash (key);

    for (i = 0; i < d->size; i++)
    {
	if (!d->key[i])
	    continue;

	/* Compare hash */
	if (hash == d->hash[i])
      	{
	    /* Compare string, to avoid hash collisions */
	    if (!strcmp (key, d->key[i]))
	    {
		/* Found key */
		break;
	    }
	}
    }

    if (i >= d->size)
	/* Key not found */
	return;

    free (d->key[i]);

    d->key[i] = NULL;
    if (d->val[i])
    {
	free (d->val[i]);
	d->val[i] = NULL;
    }

    d->hash[i] = 0;
    d->n --;
}
开发者ID:bhull2010,项目名称:libcompizfusionconfig-packages,代码行数:42,代码来源:iniparser.c

示例8: iniparser_find_entry

int iniparser_find_entry(
	dictionary	*	ini,
	char		*	entry
)
{
	int		i ;
	int		hash ;
	int		found ;

	found = 0 ;
	hash = dictionary_hash(entry);
	for (i=0 ; i<ini->n ; i++) {
		if (hash==ini->hash[i]) {
			if (!strcmp(entry, ini->key[i])) {
				found = 1 ;
				break ;
			}
		}
	}
	return found ;
}
开发者ID:belen-albeza,项目名称:edivc,代码行数:21,代码来源:mainparse.c

示例9: output

/*--------------------------------------------------------------------------*/
LPWCHAR dictionary_get
    (LPDICTIONARY lpDict,       // Ptr to workspace dictionary
     LPWCHAR      lpwKey,
     LPWCHAR      lpwDef,
     LPINT        lpIndex)      // Ptr to index on output (may be NULL)

{
    UINT hash;
    int  i;

    Assert (lpDict NE NULL);

    // If it's valid, ...
    if (lpIndex NE NULL)
        // Initialize it
        *lpIndex = -1;

    // Hash the key
    hash = dictionary_hash (lpwKey);

    for (i = 0; i < lpDict->size; i++)
    if (lpDict->key[i] NE NULL)
    {
        /* Compare hash */
        if (hash EQ lpDict->hash[i])
        {
            /* Compare string, to avoid hash collisions */
            if (!lstrcmpW (lpwKey, lpDict->key[i]))
            {
                if (lpIndex NE NULL)
                    *lpIndex = i;

                return lpDict->val[i];
            } // End IF
        } // End IF
    } // End FOR/IF

    return lpwDef;
} // End dictionary_get
开发者ID:PlanetAPL,项目名称:nars2000,代码行数:40,代码来源:dictionary.c

示例10: main


//.........这里部分代码省略.........
        }

        /* Change the file mode mask */
        umask(0);

        openlog ("notifmed", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL0);
        syslog (LOG_INFO, "Program started by user %d", getuid ());

        if (config_preceeds) {
                char * home = getenv("HOME");
                char * home_path_config = malloc(snprintf(NULL, 0, "%s/%s", home, ".notifmedrc") + 1);
                sprintf(home_path_config, "%s/%s", home, ".notifmedrc");

                if (file_exists(home_path_config)) {
                        dict = iniparser_load(home_path_config);
                } else if (file_exists("/etc/notifmed.rc")) {
                        dict = iniparser_load("/etc/notifmed.rc");
                        /* a config file could also be given as argument
                           } else if (file_exists()) {
                           dict = iniparser_load();*/
                } else {
                        syslog (LOG_INFO, "No configuration file found.");
                        syslog (LOG_INFO, "Using defaults:");
                        syslog (LOG_INFO, "    port = 5586 ; notification_timeout = 5");
                }

                if (!dict) {
                        syslog (LOG_ERR, "Dictionary configuration file problem.");
                        closelog();
                        exit(EXIT_FAILURE);
                }

                int i;
                unsigned int hh=dictionary_hash("server");
                for ( i=0 ; (i<dict->n) && (hh!=dict->hash[i]) ; i++);
                // No "server" section found
                if( i == dict->n ) {
                        syslog (LOG_INFO, "No server section found.");
                        syslog (LOG_INFO, "Using defaults:");
                        syslog (LOG_INFO, "    port = 5586 ; notification_timeout = 5");
                }

                for ( i++ ; ( i < dict->n ) && strncmp(dict->key[i],"server:",6) == 0 ; i++ ) {
                        if (strcmp(dict->key[i],"server:port") == 0) {
                                port = atoi(dict->val[i]);
                        } else if (strcmp(dict->key[i],"server:notification_timeout") == 0) {
                                notification_timeout = atoi(dict->val[i]);
                        }
                }
        }
        syslog (LOG_INFO, "Config found: port=%i - notification_timeout=%i", port, notification_timeout);

        /* Create a new SID for the child process */
        sid = setsid();
        if (sid < 0) {
                syslog (LOG_ERR, "Cannot create a new SID.");
                closelog();
                exit(EXIT_FAILURE);
        }

        // Preparing the network part
        sockfd = socket(AF_INET, SOCK_STREAM, 0);
        if (sockfd < 0) {
                syslog (LOG_ERR, "Cannot open the socket.");
                closelog();
                exit(EXIT_FAILURE);
开发者ID:gsacre,项目名称:notify_me,代码行数:67,代码来源:notifmed.c

示例11: dictionary_set

/*--------------------------------------------------------------------------*/
int dictionary_set(dictionary* d, const char* key, const char* val)
{
    size_t      i ;
    unsigned    hash ;

    if (d==NULL || key==NULL)
    {
        return -1 ;
    }

    /* Compute hash for this key */
    hash = dictionary_hash(key) ;

    /* Find if value is already in dictionary */
    if (d->n>0)
    {
        for (i=0 ; i<(size_t)d->size ; i++)
        {
            if (d->key[i]==NULL)
            {
                continue ;
            }

            if (hash==d->hash[i])   /* Same hash value */
            {
                if (!strcmp(key, d->key[i]))     /* Same key */
                {
                    /* Found a value: modify and return */
                    if (d->val[i]!=NULL)
                    {
                        free(d->val[i]);
                    }

                    d->val[i] = val ? xstrdup(val) : NULL ;
                    /* Value has been modified: return */
                    return 0 ;
                }
            }
        }
    }

    /* Add a new value */
    /* See if dictionary needs to grow */
    if (d->n==d->size)
    {

        /* Reached maximum size: reallocate dictionary */
        d->val  = (char** )mem_double(d->val,  d->size * sizeof *d->val) ;
        d->key  = (char** )mem_double(d->key,  d->size * sizeof *d->key) ;
        d->hash = (unsigned* )mem_double(d->hash, d->size * sizeof *d->hash) ;

        if ((d->val==NULL) || (d->key==NULL) || (d->hash==NULL))
        {
            /* Cannot grow dictionary */
            return -1 ;
        }

        /* Double size */
        d->size *= 2 ;
    }

    /* Insert key in the first empty slot. Start at d->n and wrap at
       d->size. Because d->n < d->size this will necessarily
       terminate. */
    for (i=d->n ; d->key[i] ; )
    {
        if(++i == (size_t)d->size)
        {
            i = 0;
        }
    }

    /* Copy key */
    d->key[i]  = xstrdup(key);
    d->val[i]  = val ? xstrdup(val) : NULL ;
    d->hash[i] = hash;
    d->n ++ ;
    return 0 ;
}
开发者ID:freeeyes,项目名称:PSS,代码行数:80,代码来源:dictionary.c

示例12: dictionary_set

/*--------------------------------------------------------------------------*/
dictionary_value* dictionary_set(dictionary * d, const char * key, char * val, int type, void* ptr,void (*cb)(void))
{
  int i;
  unsigned  hash;

  if (d==NULL || key==NULL)
    return NULL ;

  /* Compute hash for this key */
  hash = dictionary_hash(key) ;
  /* Find if value is already in dictionary */
  if (d->n>0) {
    for (i=0 ; i<d->size ; i++) {
      if (d->key[i]==NULL)
        continue ;
      if (hash==d->hash[i]) { /* Same hash value */
        if (!strcmp(key, d->key[i])) { /* Same key */
          /* Found a value: modify and return */
          if (d->values[i].val!=NULL)
            free(d->values[i].val);

          d->values[i].val  = (val != NULL) ? xstrdup(val) : NULL ;
          /* Value has been modified: return */
          return &d->values[i];
        }
      }
    }
  }

  /* Add a new value */
  /* See if dictionary needs to grow */
  if (d->n==d->size) {
    /* Reached maximum size: reallocate dictionary */
    d->values = (dictionary_value *)mem_double(d->values,  d->size * sizeof(dictionary_value*)) ;
    d->key    = (char **)mem_double(d->key,  d->size * sizeof(char*)) ;
    d->hash   = (unsigned int *)mem_double(d->hash, d->size * sizeof(unsigned)) ;
    if ((d->values==NULL) || (d->key==NULL) || (d->hash==NULL)) {
        /* Cannot grow dictionary */
        return NULL;
    }
    /* Double size */
    d->size *= 2 ;
  }

  /* Insert key in the first empty slot */
  for (i=0 ; i<d->size ; i++) {
    if (d->key[i]==NULL) {
        /* Add key here */
        break ;
    }
  }
  /* Copy key */
  d->key[i]         = xstrdup(key);
  d->values[i].val  = (val != NULL) ? xstrdup(val) : NULL;
  d->values[i].type = type;
  d->values[i].callback = NULL;
  d->values[i].rw = 0;
  d->values[i].scope = -1;
  d->values[i].ptr  = ptr;
  d->hash[i]        = hash;
  d->n ++ ;

  return &d->values[i] ;
}
开发者ID:AdamCDunlap,项目名称:hmc-robot-drivers,代码行数:65,代码来源:dictionary.c

示例13: dictionary_set

/*--------------------------------------------------------------------------*/
static void
dictionary_set (dictionary * d, char * key, char * val)
{
    int         i;
    unsigned    hash;

    if (!d || !key)
	return;

    /* Compute hash for this key */
    hash = dictionary_hash (key);

    /* Find if value is already in blackboard */
    if (d->n > 0)
    {
	for (i = 0; i < d->size; ++i)
	{
	    if (!d->key[i])
		continue;

	    if (hash == d->hash[i])
    	    {
		/* Same hash value */
	    	if (!strcmp (key, d->key[i]))
		{
		    /* Same key */
		    /* Found a value: modify and return */
		    if (d->val[i])
			free (d->val[i]);

		    d->val[i] = val ? strdup (val) : NULL;
		    /* Value has been modified: return */
		    return;
		}
	    }
	}
    }

    /* Add a new value */
    /* See if dictionary needs to grow */
    if (d->n == d->size)
    {
	/* Reached maximum size: reallocate blackboard */
	d->val  = (char **) mem_double (d->val,  d->size * sizeof (char*));
	d->key  = (char **) mem_double (d->key,  d->size * sizeof (char*));
	d->hash = (unsigned int *) mem_double (d->hash,
					       d->size * sizeof (unsigned));

	/* Double size */
	d->size *= 2;
    }

    /* Insert key in the first empty slot */
    for (i = 0; i < d->size; ++i)
    {
	if (!d->key[i])
	{
	    /* Add key here */
    	    break;
	}
    }

    /* Copy key */
    d->key[i]  = strdup (key);
    d->val[i]  = val ? strdup (val) : NULL;
    d->hash[i] = hash;
    ++d->n;
}
开发者ID:Jubei-Mitsuyoshi,项目名称:aaa-compiz,代码行数:69,代码来源:iniparser.c

示例14: Test_dictionary_hash

void Test_dictionary_hash(CuTest *tc)
{
    /* NULL test */
    CuAssertIntEquals(tc, 0, dictionary_hash(NULL));
}
开发者ID:DelusionalLogic,项目名称:iniparser,代码行数:5,代码来源:test_dictionary.c


注:本文中的dictionary_hash函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。