ReplyMap.swift (631B)
1 // 2 // ReplyMap.swift 3 // damus 4 // 5 // Created by William Casarin on 2022-04-19. 6 // 7 8 import Foundation 9 10 class ReplyMap { 11 var replies: [NoteId: Set<NoteId>] = [:] 12 13 func lookup(_ id: NoteId) -> Set<NoteId>? { 14 return replies[id] 15 } 16 17 private func ensure_set(id: NoteId) { 18 if replies[id] == nil { 19 replies[id] = Set() 20 } 21 } 22 23 @discardableResult 24 func add(id: NoteId, reply_id: NoteId) -> Bool { 25 ensure_set(id: id) 26 if (replies[id]!).contains(reply_id) { 27 return false 28 } 29 replies[id]!.insert(reply_id) 30 return true 31 } 32 }