mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Rename *LookupTable data structures to *Map.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// RelatedObjectsMap.swift
|
||||
// RSDatabase
|
||||
//
|
||||
// Created by Brent Simmons on 9/10/17.
|
||||
// Copyright © 2017 Ranchero Software, LLC. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
// Map objectID to [DatabaseObject] (related objects).
|
||||
|
||||
public struct RelatedObjectsMap {
|
||||
|
||||
private let dictionary: [String: [DatabaseObject]] // objectID: relatedObjects
|
||||
|
||||
init(relatedObjects: relatedObjects, lookupTable: LookupTable) {
|
||||
|
||||
var d = [String: [DatabaseObject]]()
|
||||
|
||||
let relatedObjectsDictionary = relatedObjects.dictionary()
|
||||
let objectIDs = lookupTable.objectIDs()
|
||||
|
||||
for objectID in lookupTable.objectIDs() {
|
||||
|
||||
if let relatedObjectIDs = lookupTable[objectID] {
|
||||
let relatedObjects = relatedObjectIDs.flatMap{ relatedObjectsDictionary[$0] }
|
||||
if !relatedObjects.isEmpty {
|
||||
d[objectID] = relatedObjects
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.dictionary = d
|
||||
}
|
||||
|
||||
public func objectIDs() -> Set<String> {
|
||||
|
||||
return Set(dictionary.keys)
|
||||
}
|
||||
|
||||
public subscript(_ objectID: String) -> [DatabaseObject]? {
|
||||
get {
|
||||
return dictionary[objectID]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user