Skip to content

Commit 2314a19

Browse files
authored
feat: Rewrite the trie example (#927)
The trie example had some issues; * It did not follow the code convention in CONTRIBUTING.md * The createTrieNode used an inefficient zeroing method (looping over the entries) which also does not zero out holes in the structure (e.g. an alternative would be to use "*node = &(TrieNode){0}", but calloc does all that anyway * It used an inefficient and clumsy printArray method * It used strlen inside the algorithm; this new method could get rid of any strlen/strnlen usage (inserts/searches could be sanitized by snprintf) * This version can allow for a custom mapping function, e.g. if NULL is a valid separator (say that you want a trie for certain binary packages) * The previous version actually contained out-of-bounds array indexing; there were no checks for out-of-bound indexing and words in the word list did contain out of bounds words. It's a surprise it was working so well. * This version just returns 'int' to allow for error checks (instead of a printf inside the algorithm), and uses double pointers for return values (good practice) * The usage example contained unnecessary mallocs, switched that out for scanf. The example is just an example after all, in real applications you'd have better input sanitazion.
1 parent d017c3e commit 2314a19

File tree

2 files changed

+147
-152
lines changed

2 files changed

+147
-152
lines changed

data_structures/trie/dictionary.txt

+1-25
Original file line numberDiff line numberDiff line change
@@ -11398,7 +11398,6 @@ ancylostome
1139811398
ancylostomiasis
1139911399
ancyroid
1140011400
and
11401-
and/or
1140211401
anda
1140311402
andabata
1140411403
andabatarian
@@ -23796,8 +23795,6 @@ azymous
2379623795
b
2379723796
bhoy
2379823797
bs
23799-
b/l
23800-
b/s
2380123798
ba
2380223799
baa
2380323800
baaed
@@ -41542,10 +41539,6 @@ byzants
4154241539
bz
4154341540
c
4154441541
cs
41545-
c/d
41546-
c/f
41547-
c/m
41548-
c/o
4154941542
ca
4155041543
ca
4155141544
cacanny
@@ -126581,7 +126574,6 @@ hailweed
126581126574
haily
126582126575
haimsucken
126583126576
hain
126584-
hain"t
126585126577
haint
126586126578
hainberry
126587126579
hainch
@@ -128730,7 +128722,6 @@ hdlc
128730128722
hdqrs
128731128723
hdwe
128732128724
he
128733-
he"ll
128734128725
hed
128735128726
hell
128736128727
hes
@@ -139010,7 +139001,6 @@ ill
139010139001
im
139011139002
is
139012139003
ive
139013-
i/c
139014139004
ia
139015139005
iago
139016139006
iamatology
@@ -145956,7 +145946,6 @@ inpours
145956145946
inpush
145957145947
input
145958145948
inputs
145959-
input/output
145960145949
inputfile
145961145950
inputs
145962145951
inputted
@@ -151770,7 +151759,6 @@ isuretine
151770151759
isuroid
151771151760
isz
151772151761
it
151773-
it"ll
151774151762
itd
151775151763
itll
151776151764
its
@@ -155260,7 +155248,6 @@ kb
155260155248
kbar
155261155249
kbps
155262155250
kc
155263-
kc/s
155264155251
kcal
155265155252
kea
155266155253
keach
@@ -156978,7 +156965,6 @@ klva
156978156965
klystron
156979156966
klystrons
156980156967
km
156981-
km/sec
156982156968
kmel
156983156969
kmet
156984156970
kmole
@@ -158105,7 +158091,6 @@ lenvoy
158105158091
loeil
158106158092
ls
158107158093
ltre
158108-
l/w
158109158094
la
158110158095
laager
158111158096
laagered
@@ -164745,8 +164730,6 @@ ller
164745164730
lloyds
164746164731
llyn
164747164732
lm
164748-
lm/ft
164749-
lm/m
164750164733
ln
164751164734
lndg
164752164735
lnr
@@ -167403,7 +167386,6 @@ lyttas
167403167386
lyxose
167404167387
m
167405167388
ms
167406-
m/s
167407167389
ma
167408167390
maam
167409167391
maad
@@ -185958,8 +185940,6 @@ n
185958185940
ngana
185959185941
nimporte
185960185942
ns
185961-
n/a
185962-
n/f
185963185943
na
185964185944
naa
185965185945
naam
@@ -198979,8 +198959,6 @@ oclock
198979198959
oer
198980198960
oertop
198981198961
os
198982-
o/c
198983-
o/s
198984198962
oad
198985198963
oadal
198986198964
oaf
@@ -345815,8 +345793,6 @@ vyingly
345815345793
vyrnwy
345816345794
w
345817345795
ws
345818-
w/
345819-
w/o
345820345796
wa
345821345797
wa
345822345798
waac
@@ -354932,4 +354908,4 @@ zymurgy
354932354908
zythem
354933354909
zythum
354934354910
zyzzyva
354935-
zyzzyvas
354911+
zyzzyvas

0 commit comments

Comments
 (0)