Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Simple implementation of trie data structure in C

NotificationsYou must be signed in to change notification settings

ashinkarov/trie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This a simple implementation oftriedata structure in C99. This implementation allows to store sequences ofint-s, however one can easy trigger a type ofsymb instruct trie.

The library includes a simple test-case in the trie.c. In order to makeit work, runmake test.

Usage

Currently an implemetation provides interfaces to storechar based strings in thetrie, attaching to each word some information ofssize_t type. Forexample, consider the following case:

#include<stdio.h>#include<string.h>#include<unistd.h>#include<stdlib.h>#include"trie.h"/* some values, we want to attach to every   word in the trie data base.  */enumtype_of_word {type_a,type_b};intmain (intargc,char*argv[]){intret=EXIT_SUCCESS;ssize_tres;/* Initialize new trie.  */tructtrie*dict=trie_new ();if (argc <=1)    {      (void)fprintf (stderr,"usage: %s word to find\n",argv[0]);ret=EXIT_FAILURE;      gotoout;    }/* Add two words of two different types.  */trie_add_word (dict,"hello",strlen ("hello"), (ssize_t)type_a);trie_add_word (dict,"hell",strlen ("hell"), (ssize_t)type_b);printf ("Printing the trie.\n");trie_print (dict);/* Search the argument in the trie and detect a type of it.  */res=trie_search (dict,argv[1],strlen (argv[1]));printf ("searching '%s' in the database -- %s\n",argv[1],res!=TRIE_NOT_LAST    ? (enumtype_of_word)res==type_a ?"yes, type A" :"yes, type B"    :"no");out:trie_free (dict);returnret;}

As the type of information you attach is a transparentsize_t we needto dedicate one symbol, whic would denote that a certain symbol isnotlast. MacroTRIE_NOT_LAST serves this purpose.

Tha implementation is valgrinded, and is compiled at strictes gcc warninglevel.

Send your suggestions or patches.

About

Simple implementation of trie data structure in C

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp