SplayDict
SplayDict written in Swift, is a collection type like special ordered set. It's based on Splay tree which reflects tendency of search input data.
What is SplayDict?
SplayDict is Dictionary using splay tree, not red-black tree. Due to attribution of splay tree, it is very fast to get data searched frequently.
In real world, so many search are requested. And many people requset a same(or similar) data. Every request, every new search. It's very consumptively.
Using SplayDict, it's not waste of time. It takes a very short time to get data searched frequently. (But, It takes a little more time to find data searched occasionally.) According to Pareto's law, using SplayDict makes a program be productive, and even faster.
TODO
- SplayTree
- flatMap
- SplayDict to Json
- Subscript
- More methods
- Adopt protocols such as CustomStringConvertible, Sequence, etc.
Usage
- declaration
var a: SplayDict<Int, Double> = SplayDict() // make a empty splay set.
var b = SplayDict([1, 3, 2]) // make a set which contains 1, 2, 3.
// and more constructor is building...
- insert
var a: SplayDict<Int, Int> = SplayDict()
a.insert(key: 3, value: 7)
// Insert [3 : 7] into SplayDict.
a[5] = 12
// Insert [5 : 12] into SplayDict.
// If you want to insert key which is already exists,
// then being value is replaced with newValue.
- top
_ = a.top
// Return a top element of SplayDict.
// It's a latest searched data.
// Read-only property
- find
var a: SplayDict<Int, String> = SplayDict()
let value: String? = a.find(key: 7)
// Return value if search value exists, else return nil.
// And this make searched key(or nearest key) be on a top of SplayDict.
- delete
a.delete(key: 5)
// Delete element corresponded with key in SplayDict.
// Make a biggest key under input be a top element.
- indexOf
var a: SplayDict<Int, Double> = SplayDict()
let value: Double? = a.indexOf(3)
// Return n-th value if SplayDict.
// If index is out of range, returns nil.
- reverse
a.reverse(from: 3, to: 6)
// Reverse elements. (from 3 to 6)
// Implement using Lazy Propagtion.
// example
// Let splay set consists of [0, 1, 2, 3, 4, 5, 6].
// reverse(from: 3, to : 6).
// The result is [0, 1, 2, 6, 5, 4, 3].
Requirement
- iOS 10.0+
- Xcode 9+
SplayDict is available through CocoaPods. To install it, simply add the following line to your Podfile:
Installation
pod 'SplayDict'
Contact
QuqqU(KiUng Jung)
License
Copyright QuqqU
(KiUng Jung) 2018 ~
SplayDict is available under the MIT
license. See the LICENSE file for more info.