Exemple #1
0
int main(int argc, char *argv[])
{
	FILE *in = stdin;
	char buf[0x4000]; /* limited to 16K character word length */
	cp_avltree *wordlist;
	cp_avltree *freqlist;
	int count = 0;
	int one = 1;
	int *wc;

	if (argc > 1) 
	{
		in = fopen(argv[1], "r");
		if (in == NULL)
		{
			fprintf(stderr, "can\'t open %s\n", argv[1]);
			exit(1);
		}
	}
	
	/* wordlist keys are distinct */
	wordlist = 
		cp_avltree_create_by_option(COLLECTION_MODE_NOSYNC | 
									COLLECTION_MODE_COPY | 
									COLLECTION_MODE_DEEP, 
									(cp_compare_fn) strcmp, 
									(cp_copy_fn) strdup, free, 
									(cp_copy_fn) intdup, free);
	
	while ((fscanf(in, "%s", buf)) != EOF)
	{
		filter_string(buf, PUNCT);
		to_lowercase(buf);
		wc = cp_avltree_get(wordlist, buf);
		if (wc) 
			(*wc)++;
		else
			cp_avltree_insert(wordlist, buf, &one);
		count++;
	}

	fclose(in);

	/* frequency list entry keys are not distinct */
	freqlist = 	
		cp_avltree_create_by_option(COLLECTION_MODE_NOSYNC | 
									COLLECTION_MODE_MULTIPLE_VALUES,
									(cp_compare_fn) freqcmp, 
									NULL, NULL, NULL, NULL);
	
	cp_avltree_callback(wordlist, add_freq, freqlist);
	cp_avltree_callback(freqlist, print_word_freq, &one);
	printf("%d words, %d distinct entries\n", count, cp_avltree_count(wordlist));

	cp_avltree_destroy(freqlist);
	cp_avltree_destroy(wordlist);

	return 0;
}
Exemple #2
0
/* callback for building frequency list from word list */
int add_freq(void *entry, void *tree)
{
	cp_avltree *freq = tree;
	cp_avlnode *node = entry;
	cp_avltree_insert(freq, node->value, node->key);

	return 0;
}
Exemple #3
0
allocate_splice_elements_t* allocate_new_splice(unsigned int chromosome, unsigned char strand, 
						size_t end, size_t start, 
						size_t splice_start, size_t splice_end, 
						allocate_splice_elements_t* chromosome_avls_p){
  node_element_splice_t *node;

  node = (node_element_splice_t *)cp_avltree_get(chromosome_avls_p[chromosome].avl_splice, (void *)start);

  if(node == NULL) {
    node = cp_avltree_insert(chromosome_avls_p[chromosome].avl_splice, (void *)start, (void *)start);
    node->splice_start_extend = splice_start;
  }
  
  node = search_and_insert_end_splice(chromosome, strand, end, splice_start, splice_end, node);

  return chromosome_avls_p;
}