Boost Trie
Transcript of Boost Trie
-
8/16/2019 Boost Trie
1/20
Boost TrieFrom Data Structure to C++
Library
Cosmin Boacă
-
8/16/2019 Boost Trie
2/20
About e
• Cosmin Boaca
• !assionate about algorit"ms# $atastructures an$ big $ata
• Sil%er & Bron'e me$al at (ational)lym*ia$ in n,ormatics
•
nterns"i*s at ntel# Faceboo- an$A$obe
• C++ ,ananatic/
-
8/16/2019 Boost Trie
3/20
Trie
• n memory $ata structure use$ ,orstoring strings in sorte$ or$er
-
8/16/2019 Boost Trie
4/20
Trie
• n memory $ata structure use$ ,orstoring strings in sorte$ or$er
• )*erations su**orte$ – nsert-ey/
– Fin$-ey/
– 0rase-ey/
– LongestCommon!re2-ey/
– terating o%er t"e -eys in ascen$ing &$escen$ing or$er
-
8/16/2019 Boost Trie
5/20
Trie
• 02ecution time ,or all o*erations is*ro*ortional to t"e lengt" o, t"e -ey#regar$less o, t"e number o, -eys t"atare currently store$ in t"e $atastructure
-
8/16/2019 Boost Trie
6/20
Trie
-
8/16/2019 Boost Trie
7/20
Trie
(o$e structure3
struct Trie bool is6ey0n$7
Trie 8sons :;
-
8/16/2019 Boost Trie
8/20
Trie
• Do>nsi$es – ?ig" memory consum*tion eac" no$e
"as SA sons/ >"ere SA is t"e
$imension o, t"e al*"abet – ost o, t"ose sons arent e%en use$
-
8/16/2019 Boost Trie
9/20
From $ata structure tolibrary
• euirements ,or a C++ library – Fle2ibility
• T"e user s"oul$ be able to $ene "is o>n
allocators an$ *lug t"em into t"e library>it"out too muc" eort use,ul in embe$$e$systems es*ecially/
• A$%ance$ ,eatures suc" t"e one abo%e/
s"oul$ be trans*arent to users t"at $ontnee$ t"em
-
8/16/2019 Boost Trie
10/20
From $ata structure tolibrary
• euirements ,or a C++ library – enerality
• T"e library s"oul$ >or- >it" most o, i$eally
all/ t"e user $ene$ ty*es reuiring aminimal eort ,rom t"e user *ers*ecti%e
-
8/16/2019 Boost Trie
11/20
From $ata structure tolibrary
• euirements ,or a C++ library – 0Eciency
• T"e library co$e s"oul$ *er,orm as goo$ as
a co$e t"at is >ritten ,or sol%ing a s*ecic*roblem
• Abstractions use$ s"oul$ bring as lo>*enalty as *ossible
-
8/16/2019 Boost Trie
12/20
From $ata structure tolibrary
• euirements ,or a C++ library – ntero*erability >it" stan$ar$ library
• , one >ants to s>itc" ,rom e2isting co$e
using st$33ma* to boost33triema* "e s"oul$be able to $o t"is by Gust te2tually re*lacingma* >it" triema*
• Algorit"ms ,rom Halgorit"mI "ea$er s"oul$
>or- >it" t"e $ata structures ,rom t"elibrary
• terators e2*ose$ s"oul$ com*ly to C++iterator stan$ar$ "ar$er t"an you >oul$
e%er imagine/
-
8/16/2019 Boost Trie
13/20
C++ iterator s*ecication
-
8/16/2019 Boost Trie
14/20
From $ata structure tolibrary
• euirements ,or Boost Trie – T"e same $ata structure s"oul$ be
Je2ible enoug" to be use$ as container
,or triema*&multima*# set&multiset – 6eys inserte$ s"oul$ be any -in$ o,
iterable structures inclu$ing user
$ene$ structures/ >"ic" iterate o%erany -in$ o, com*arable ty*es
– Better *er,ormance in terms o, time an$memory t"an t"e eui%alent stan$ar$
containers
-
8/16/2019 Boost Trie
15/20
From $ata structure tolibrary
• C"allenges – !er,ormance
• n *ractice# >"en -eys arent c"aracters t"e
usual Trie "as *oor *er,ormance in terms o,bot" memory consum*tion an$ e2ecutiontime
• aintaining bot" *er,ormance an$
generality is "ar$ an$ it reuires a lot o,tec"nical $e*t" an$ $ee* un$erstan$ing o,t"e language.
-
8/16/2019 Boost Trie
16/20
From $ata structure tolibrary
• C"allenges – terators
• T"e most com*licate$ ,eature to im*lement
an$ su**ort are C++ iterators• T"ere are $e$icate$ libraries ,or t"is
Boost.terator/
-
8/16/2019 Boost Trie
17/20
From $ata structure tolibrary
• C"allenges – enerality
• ?an$ling o, alocation & $ealocation using
allocators instea$ o, ne> & $elete• ?an$ling %alue ty*es >"ic" are not $e,ault
constructible
• ?an$ling -ey ty*es >"ic" are not
com*arable & $e,ault constructible
-
8/16/2019 Boost Trie
18/20
From $ata structure tolibrary
• )*timi'ations – Ksing Boost.ntrusi%e.Set as no$e
container instea$ o, st$33set
– aritions o, Trie• Com*act Trie
• Burst Trie
• Some ot"er Trie t"at "a%e im*lemente$ att"e moment
-
8/16/2019 Boost Trie
19/20
-
8/16/2019 Boost Trie
20/20
Boost %s Cor*orate
Boost
• Best *eo*le in C++o%er t"e >orl$
• A lot to learn about C++ an$ *rogramming ingeneral
• ?ar$core co$e re%ie>
• nsanely "ig" co$euality stan$ar$s
• emote collaboration
Corporate• A%erage *rogrammers
• Ksing only a smallsubset o, C++,eatures
• ore rela2e$ co$ere%ie>
• Co$e uality
stan$ar$s em*"asi'erea$ability an$maintainability
• Por- en%ironment