@@ -3,16 +3,22 @@ import FeaturevisorTypes
3
3
public class DatafileReader {
4
4
let schemaVersion : String
5
5
let revision : String
6
- let attributes : [ Attribute ]
7
- let segments : [ Segment ]
8
- let features : [ Feature ]
6
+ let attributes : [ AttributeKey : Attribute ]
7
+ let segments : [ SegmentKey : Segment ]
8
+ let features : [ FeatureKey : Feature ]
9
9
10
10
init ( datafileContent: DatafileContent ) {
11
11
self . schemaVersion = datafileContent. schemaVersion
12
12
self . revision = datafileContent. revision
13
- self . segments = datafileContent. segments
14
- self . attributes = datafileContent. attributes
15
- self . features = datafileContent. features
13
+ self . segments = Dictionary (
14
+ uniqueKeysWithValues: datafileContent. segments. map { ( $0. key, $0) }
15
+ )
16
+ self . attributes = Dictionary (
17
+ uniqueKeysWithValues: datafileContent. attributes. map { ( $0. key, $0) }
18
+ )
19
+ self . features = Dictionary (
20
+ uniqueKeysWithValues: datafileContent. features. map { ( $0. key, $0) }
21
+ )
16
22
}
17
23
18
24
public func getRevision( ) -> String {
@@ -24,18 +30,18 @@ public class DatafileReader {
24
30
}
25
31
26
32
public func getAllAttributes( ) -> [ Attribute ] {
27
- return self . attributes
33
+ return Array ( attributes. values )
28
34
}
29
35
30
36
public func getAttribute( _ attributeKey: AttributeKey ) -> Attribute ? {
31
- return self . attributes. first ( where : { $0 . key == attributeKey } )
37
+ return self . attributes [ attributeKey]
32
38
}
33
39
34
40
public func getSegment( _ segmentKey: SegmentKey ) -> Segment ? {
35
- return segments. first ( where : { $0 . key == segmentKey } )
41
+ return segments [ segmentKey]
36
42
}
37
43
38
44
public func getFeature( _ featureKey: FeatureKey ) -> Feature ? {
39
- return features. first ( where : { $0 . key == featureKey } )
45
+ return features [ featureKey]
40
46
}
41
47
}
0 commit comments