Professional Documents
Culture Documents
London, 2013
Igor Petruk
Examples
Igor Petruk
Igor Petruk
Goals of the presentation Find data structures you like (maybe reminds a part of your system)
Igor Petruk
Goals of the presentation Find data structures you like (maybe reminds a part of your system) Make a note with their names
Igor Petruk
Goals of the presentation Find data structures you like (maybe reminds a part of your system) Make a note with their names Become aware of availability of the trickiest data structures
Igor Petruk
Goals of the presentation Find data structures you like (maybe reminds a part of your system) Make a note with their names Become aware of availability of the trickiest data structures Discover some cool ways to use them
Igor Petruk
Goals of the presentation Find data structures you like (maybe reminds a part of your system) Make a note with their names Become aware of availability of the trickiest data structures Discover some cool ways to use them Get inspired to practice data structure driven development
Igor Petruk
Goals of the presentation Find data structures you like (maybe reminds a part of your system) Make a note with their names Become aware of availability of the trickiest data structures Discover some cool ways to use them Get inspired to practice data structure driven development Not a goal of the presentation Trying to remember what I say
Igor Petruk
What is a data structure? data structure is a particular way of storing and organizing data in a computer so that it can be used eciently.
Igor Petruk
What is a data structure? data structure is a particular way of storing and organizing data in a computer so that it can be used eciently. Built of Data Behaviour
Igor Petruk
What is a data structure? data structure is a particular way of storing and organizing data in a computer so that it can be used eciently. Built of Data Behaviour They can
Igor Petruk
What is a data structure? data structure is a particular way of storing and organizing data in a computer so that it can be used eciently. Built of Data Behaviour They can Be hard to imagine Be complex to understand Solve your problem in one go
Igor Petruk
Igor Petruk
Igor Petruk
Igor Petruk
Igor Petruk
Igor Petruk
Igor Petruk
Igor Petruk
Probabilistic
Igor Petruk
MultiSet
What is it A set Each value contains a counter
Igor Petruk
MultiSet
What is it A set Each value contains a counter Usage Statistics
Put values in Get element occurence count
Igor Petruk
MultiSet
What is it A set Each value contains a counter Usage Statistics
Put values in Get element occurence count
Save memory
Still using a set
Igor Petruk
MultiSet
What is it A set Each value contains a counter Usage Statistics
Put values in Get element occurence count
Save memory
Still using a set
Igor Petruk
MultiSet
What is it A set Each value contains a counter Usage Statistics
Put values in Get element occurence count
Save memory
Still using a set
Maintain leaders
Put values in realtime Use max-rst iterator
Igor Petruk
Igor Petruk
Igor Petruk
Usage As a map
No collisions with linear search in bucket No rebalancing
Igor Petruk
Usage As a map
No collisions with linear search in bucket No rebalancing
Prex search
Best support for this operation
Igor Petruk
Usage As a map
No collisions with linear search in bucket No rebalancing
Prex search
Best support for this operation
Compression
If prexes are shared
Igor Petruk
Usage As a map
No collisions with linear search in bucket No rebalancing
Prex search
Best support for this operation
Compression
If prexes are shared
Splay tree
Igor Petruk
Splay tree
Igor Petruk
Splay tree
Igor Petruk
Cache
Cache Cache is not a BIG THING Caches that are as lightweight and simple as a map are available (Guava)
Igor Petruk
Cache
Cache Cache is not a BIG THING Caches that are as lightweight and simple as a map are available (Guava) Data Simple trees, splay trees Databases Files O-heap
Igor Petruk
Cache
Igor Petruk
Cache
Write strategy
Read-only Write through Write behind
Igor Petruk
Cache
Write strategy
Read-only Write through Write behind
Eviction strategy
LRU MRU LFU Random Garbage collector driven Multi Queue
Igor Petruk
Cache
Complex?
Igor Petruk
Cache
Complex? LoadingCache<Key, Graph> graphs = CacheBuilder.newBuilder() .maximumSize(1000) .expireAfterWrite(10, TimeUnit.MINUTES) . build( new CacheLoader<Key, Graph>() { public Graph load(Key key) throws AnyException { return createExpensiveGraph(key); } });
Igor Petruk
Cache
Usage other then obvious Protecting against eventual consistency issues Batching Memoization Dynamic programming Concurrent synchronization
Igor Petruk
View
Igor Petruk
View
View Is this a data structure? YES/NO We have the data (somewhere) We have the behaviour Why copy?
Igor Petruk
View
Igor Petruk
View
Igor Petruk
View
Usage See a list as a map Process only needed part of data Perform multiple operations together
Each operation produces a wrapper Final operation - copy
Igor Petruk
View
Usage See a list as a map Process only needed part of data Perform multiple operations together
Each operation produces a wrapper Final operation - copy
Does anyone know how to concat two immutable lists with O(1) complexity?
Igor Petruk
View
Usage See a list as a map Process only needed part of data Perform multiple operations together
Each operation produces a wrapper Final operation - copy
Does anyone know how to concat two immutable lists with O(1) complexity?
Combine data structures
Igor Petruk
View
Usage See a list as a map Process only needed part of data Perform multiple operations together
Each operation produces a wrapper Final operation - copy
Does anyone know how to concat two immutable lists with O(1) complexity?
Combine data structures
Igor Petruk
Igor Petruk
Igor Petruk
Igor Petruk
Igor Petruk
Bloom lter
Bloom lter A probabilistic set Can represent set of elements from innite universe
Igor Petruk
Bloom lter
Bloom lter A probabilistic set Can represent set of elements from innite universe Strict test if the set does NOT contain the element
Igor Petruk
Bloom lter
Bloom lter A probabilistic set Can represent set of elements from innite universe Strict test if the set does NOT contain the element Probabilistic test if the set contains the element
Igor Petruk
Bloom lter
Bloom lter A probabilistic set Can represent set of elements from innite universe Strict test if the set does NOT contain the element Probabilistic test if the set contains the element Internals An array of m bits k dierent hash functions, that produce values from 0 to m-1 Extendable to counting Bloom lter which supports deletion
Igor Petruk
Bloom lter
Bloom lter A probabilistic set Can represent set of elements from innite universe Strict test if the set does NOT contain the element Probabilistic test if the set contains the element Internals An array of m bits k dierent hash functions, that produce values from 0 to m-1 Extendable to counting Bloom lter which supports deletion Notable usages Apache Cassandra and Google BigTable
Test if the record can be on the disk If it can - fetch it from the disk If not, then we dont have to trigger a disk operation
Igor Petruk Data Structures and beyond
Stream
Igor Petruk
Stream
Stream List Evaluator in tail Can be innite Usage Good abstraction for innite computation that can be consumed by list processing routines
Igor Petruk
Stream
Stream List Evaluator in tail Can be innite Usage Good abstraction for innite computation that can be consumed by list processing routines If internal list is a linked list, then the GC can gather already processed data
Igor Petruk
Stream
Stream List Evaluator in tail Can be innite Usage Good abstraction for innite computation that can be consumed by list processing routines If internal list is a linked list, then the GC can gather already processed data Change denition of int b(int) to Stream<Integer> b()
Igor Petruk
Stream
Stream List Evaluator in tail Can be innite Usage Good abstraction for innite computation that can be consumed by list processing routines If internal list is a linked list, then the GC can gather already processed data Change denition of int b(int) to Stream<Integer> b() You still can represent input, but via generic Stream
Igor Petruk
Stream
Stream List Evaluator in tail Can be innite Usage Good abstraction for innite computation that can be consumed by list processing routines If internal list is a linked list, then the GC can gather already processed data Change denition of int b(int) to Stream<Integer> b() You still can represent input, but via generic Stream Convert one stream to another via wrappers
Igor Petruk
Option
Igor Petruk
Option
Option One or zero element collection Null is no more! JK, easy conversion from null to Option and back
Igor Petruk
Option
Option One or zero element collection Null is no more! JK, easy conversion from null to Option and back Forces you to unbox the value before usage Usage
Igor Petruk
Option
Option One or zero element collection Null is no more! JK, easy conversion from null to Option and back Forces you to unbox the value before usage Usage Do you have and element or not? Is the computation sucessful or not? Is the value populated or not by user? Null safe operations within Option Available in Guava as Optional Monad
Igor Petruk