Esempio n. 1
0
void flx_bbl_init(void){
	uint16_t i;
	for(i=0; i<NUM_BBL_TREES; ++i){
		bbl_trees[i] = avl_alloc_tree((avl_compare_t)avl_bbl_cmp, (avl_freeitem_t)avl_bbl_free);
	}
	memset(&flx_bbl_cache, 0, sizeof(flx_bbl_cache));
}
Esempio n. 2
0
SeafRepoManager*
seaf_repo_manager_new (SeafileSession *seaf)
{
    SeafRepoManager *mgr = g_new0 (SeafRepoManager, 1);

    mgr->priv = g_new0 (SeafRepoManagerPriv, 1);
    mgr->seaf = seaf;

    mgr->priv->repo_tree = avl_alloc_tree ((avl_compare_t)compare_repo,
                                           NULL);

    pthread_rwlock_init (&mgr->priv->lock, NULL);

    return mgr;
}
Esempio n. 3
0
struct s_rule_link * newlink(char * rule, unsigned long pwtested)
{
    struct s_rule_link * out;

    out = xmalloc(sizeof(struct s_rule_link));
    out->rule = strdup(rule);
    out->pwtested = pwtested;
    if(out->rule == NULL)
    {
        perror("strdup");
        exit(50);
    }
    //out->coverage = avl_alloc_tree((avl_compare_t)int_cmp, (avl_freeitem_t)free);
    out->coverage = avl_alloc_tree((avl_compare_t)ptr_cmp, NULL);
    return out;
}
Esempio n. 4
0
int
daap_query_init(void)
{
  avl_node_t *node;
  struct dmap_query_field_map *dqfm;
  int i;

  dmap_query_fields_hash = avl_alloc_tree(dmap_query_field_map_compare, NULL);
  if (!dmap_query_fields_hash)
    {
      DPRINTF(E_FATAL, L_DAAP, "DAAP query init could not allocate AVL tree\n");

      return -1;
    }

  for (i = 0; dmap_query_fields[i].hash == 0; i++)
    {
      dmap_query_fields[i].hash = djb_hash(dmap_query_fields[i].dmap_field, strlen(dmap_query_fields[i].dmap_field));

      node = avl_insert(dmap_query_fields_hash, &dmap_query_fields[i]);
      if (!node)
        {
          if (errno != EEXIST)
            DPRINTF(E_FATAL, L_DAAP, "DAAP query init failed; AVL insert error: %s\n", strerror(errno));
          else
            {
              node = avl_search(dmap_query_fields_hash, &dmap_query_fields[i]);
              dqfm = node->item;

              DPRINTF(E_FATAL, L_DAAP, "DAAP query init failed; WARNING: duplicate hash key\n");
              DPRINTF(E_FATAL, L_DAAP, "Hash %x, string %s\n", dmap_query_fields[i].hash, dmap_query_fields[i].dmap_field);

              DPRINTF(E_FATAL, L_DAAP, "Hash %x, string %s\n", dqfm->hash, dqfm->dmap_field);
            }

          goto avl_insert_fail;
        }
    }

  return 0;

 avl_insert_fail:
  avl_free_tree(dmap_query_fields_hash);

  return -1;
}
Esempio n. 5
0
File: l5.c Progetto: krasm/coursera
int main(int argc, char * argv[]) {
	mpz_t p, g, h, b;
	mpz_t tmp, val;
	avl_tree_t * dict = avl_alloc_tree(l5_cmpr, NULL);

	mpz_inits(tmp, val, NULL);
	mpz_init_set_str(p, P, 10);
	mpz_init_set_str(g, G, 10);
	mpz_init_set_str(h, H, 10);
	mpz_init_set_ui(b, B20);


	for(unsigned long int i = 0; i <= B20; i++) {
		l5_lhs_t * r = l5_lhs_new(g, h, p, i);
		//gmp_printf("%Zd\n", r->value);
		avl_node_t * n = avl_insert(dict, r);
		assert(n != NULL);
	}
	for(unsigned long int i = 0; i <= B20; i++) {
		l5_lhs_t * r = l5_rhs_new(g, h, p, i);
		//gmp_printf("%Zd\n", r->value);
		avl_node_t * n = avl_search(dict, r);
		if(n != NULL) {
			l5_lhs_t * f = (l5_lhs_t*)n->item;

			mpz_t result;
			mpz_init(result);
			mpz_set_ui(result, B20);
			mpz_mul_ui(result, result, r->x);
			mpz_add_ui(result, result, f->x);

			gmp_printf("%Zd\n", result);

			exit(0);
		}
	}

	return 0;
}
Esempio n. 6
0
File: conf.c Progetto: 95ulisse/tinc
void init_configuration(avl_tree_t ** config_tree) {
	*config_tree = avl_alloc_tree((avl_compare_t) config_compare, (avl_action_t) free_config);
}
Esempio n. 7
0
int main(int argc, char ** argv)
{
	FILE * dictionnary;
	FILE * pwds;
	char line[LINELEN];
	unsigned int i,j;
	avl_tree_t * sroot;
	struct rlimit rlim;
	BLOOM_TYPE * bloom;
	BLOOM_TYPE * bloom_cityhash;

	unsigned long curhashes[MAXLEN];
	unsigned int curstart[MAXLEN];
	unsigned int maxlen;
	unsigned int maxstart;
	unsigned char ln2[LINELEN];
	unsigned int len;
    unsigned int minmatch;

	rlim.rlim_cur = MAXMEM;
	rlim.rlim_max = MAXMEM;
	if(setrlimit(RLIMIT_AS, &rlim))
	{
		perror("setrlimit");
		return 3;
	}

	if( (argc != 4) && (argc != 5) )
		usage();
	nblines = 0;

    if(argc == 5)
    {
        minmatch = atoi(argv[4]);
        if(minmatch == 0)
        {
            fprintf(stderr, "can't parse %s as int\n", argv[4]);
            return 6;
        }
    }
    else
        minmatch = 1;

	/* arbre contenant le dictionnaire pour éviter les FP */
	sroot = avl_alloc_tree((avl_compare_t)strcmp, (avl_freeitem_t)free);

	/* bloom table */
	bloom = xmalloc(BLOOM_STORAGE);
	memset(bloom, 0, BLOOM_STORAGE);
	bloom_cityhash = xmalloc(BLOOM_STORAGE);
	memset(bloom_cityhash, 0, BLOOM_STORAGE);
	
	fprintf(stderr, "%lld bytes have been allocated for bloom filters\n", BLOOM_STORAGE*2);

	if(strcmp(argv[1],"-")==0)
		dictionnary = stdin;
	else
		dictionnary = fopen(argv[1], "r");
	if(dictionnary == NULL)
	{
		perror(argv[1]);
		return 2;
	}
	pwds = fopen(argv[2], "r");
	if(pwds == NULL)
	{
		perror(argv[2]);
		return 3;
	}

	while(fgets(line, LINELEN-1, dictionnary))
	{
		len = strlen(line);
		if(len>MAXLEN)
			continue;
        if(len<minmatch)
            continue;
		nblines++;
		if(nblines % 1000000 == 0)
			fprintf(stderr, "%ldM dictionnary lines integrated\n", nblines/1000000);
		line[len-1]=0; // trim !
		SETBIT(bloom, hash(line));
		SETBIT(bloom_cityhash, cityhash(line));
		avl_insert(sroot, strdup(line));
	}
	printf("%ld lines\n", nblines);
	fclose(dictionnary);

	nbpass = 0;
	nbfp = 0;
	nbmatch = 0;
	while(fgets((char*) line, LINELEN-1, pwds))
	{
		nbpass++;
		if(nbpass % 500000 == 0)
			fprintf(stderr, "%.1fM passwords analyzed [%s]\n", ((float)nbpass)/1000000.0, argv[3]);
		maxlen = 0;
		maxstart = 0;
		memset(curstart, 0, sizeof(curstart));
		for(i=0;i<MAXLEN;i++)
			curhashes[i]=HASH_INIT;
		for(i=0;line[i] && line[i]!='\n' && (i<MAXLEN*2);i++)
		{
			curhashes[i%MAXLEN]=HASH_INIT;
			curstart[i%MAXLEN] = i;
			for(j=0;j<MAXLEN;j++)
			{
				HASH_STEP(curhashes[j],line[i]);
			}
			for(j=0;j<MAXLEN;j++)
			{
				/* si on ne bat pas le maxlen courant ça ne sert à rien */
				if( i-curstart[j]+1 < maxlen )
					continue;
				/* check bloom filter */
				if(GETBIT(bloom, curhashes[j]))
				{
					memset(ln2, 0, sizeof(ln2));
					memcpy(ln2, line+curstart[j], i-curstart[j]+1);
					if(GETBIT(bloom_cityhash, cityhash((char*)ln2)))
					{
						if(avl_search(sroot, ln2)) /* evitons les FP */
						{
							maxlen = i-curstart[j]+1;
							maxstart = curstart[j];
						}
						else
						{
							nbfp++;
						}
					}
				}
			}
		}
        if(maxlen<minmatch)
			continue;
		line[strlen((char*)line)-1] = 0;
		printf("%s\t%s\t", argv[3], line);
		if(maxstart>0)
		{
			memset(ln2, 0, sizeof(ln2));
			strncpy((char*)ln2, (char*)line, maxstart);
			printf("%s\t", ln2);
		}
		else
			printf("\t");
		if(maxstart+maxlen<strlen((char*)line))
			printf("%s\t", line + maxstart + maxlen);
		else
			printf("\t");
		line[maxstart+maxlen] = 0;
		printf("%s\t%d\n", line+maxstart, nbpass);
		nbmatch++;
	}

	fprintf(stderr, "%d passwords analyzed, %d matches, %d false positives\n", nbpass, nbmatch, nbfp);

	return 0;
}
Esempio n. 8
0
avl_tree_t *new_subnet_tree(void) {
	return avl_alloc_tree((avl_compare_t) subnet_compare, NULL);
}
Esempio n. 9
0
void init_subnets(void) {
	subnet_tree = avl_alloc_tree((avl_compare_t) subnet_compare, (avl_action_t) free_subnet);

	subnet_cache_flush();
}