File tree Expand file tree Collapse file tree 4 files changed +520
-53
lines changed Expand file tree Collapse file tree 4 files changed +520
-53
lines changed Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ /*
2
+ Queue implementation (taken from repository, needed for findPrefix())
3
+ */
4
+ public struct Queue < T> {
5
+ private var array = [ T? ] ( )
6
+ private var head = 0
7
+
8
+ public var isEmpty : Bool {
9
+ return count == 0
10
+ }
11
+
12
+ public var count : Int {
13
+ return array. count - head
14
+ }
15
+
16
+ public mutating func enqueue( element: T ) {
17
+ array. append ( element)
18
+ }
19
+
20
+ public mutating func dequeue( ) -> T ? {
21
+ guard head < array. count, let element = array [ head] else { return nil }
22
+
23
+ array [ head] = nil
24
+ head += 1
1
25
26
+ let percentage = Double ( head) / Double( array. count)
27
+ if array. count > 50 && percentage > 0.25 {
28
+ array. removeFirst ( head)
29
+ head = 0
30
+ }
31
+
32
+ return element
33
+ }
34
+
35
+ public func peek( ) -> T ? {
36
+ if isEmpty {
37
+ return nil
38
+ } else {
39
+ return array [ head]
40
+ }
41
+ }
42
+ }
2
43
/*
3
44
A Trie (Pre-fix Tree)
4
45
You can’t perform that action at this time.
0 commit comments