From 899486a162a83dd69f0c5227af58a061665879a5 Mon Sep 17 00:00:00 2001 From: Jim Wallace <james.wallace@uwaterloo.ca> Date: Thu, 4 Apr 2024 15:44:06 -0400 Subject: [PATCH] Restored --- ...nisticEphemeralVectorIndex + Codable.swift | 100 +++++++++--------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/Sources/SwiftNLP/1. Data Collection/HNSW/DeterministicEphemeralVectorIndex + Codable.swift b/Sources/SwiftNLP/1. Data Collection/HNSW/DeterministicEphemeralVectorIndex + Codable.swift index 1a1d2eaf..84459298 100644 --- a/Sources/SwiftNLP/1. Data Collection/HNSW/DeterministicEphemeralVectorIndex + Codable.swift +++ b/Sources/SwiftNLP/1. Data Collection/HNSW/DeterministicEphemeralVectorIndex + Codable.swift @@ -1,55 +1,55 @@ -//// Copyright (c) 2024 Jim Wallace -//// -//// Permission is hereby granted, free of charge, to any person -//// obtaining a copy of this software and associated documentation -//// files (the "Software"), to deal in the Software without -//// restriction, including without limitation the rights to use, -//// copy, modify, merge, publish, distribute, sublicense, and/or sell -//// copies of the Software, and to permit persons to whom the -//// Software is furnished to do so, subject to the following -//// conditions: -//// -//// The above copyright notice and this permission notice shall be -//// included in all copies or substantial portions of the Software. -//// -//// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -//// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -//// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -//// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -//// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -//// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -//// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -//// OTHER DEALINGS IN THE SOFTWARE. -//// -//// Created by Mingchung Xia on 2024-02-07. -//// +// Copyright (c) 2024 Jim Wallace // -//import Foundation +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: // -//extension DeterministicEphemeralVectorIndex: Encodable where Vector: Encodable { -// enum CodingKeys: String, CodingKey { -// case typicalNeighborhoodSize -// case vectors -// } +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. // -// public func encode(to encoder: Encoder) throws { -// var container = encoder.container(keyedBy: CodingKeys.self) -// try container.encode(typicalNeighborhoodSize, forKey: .typicalNeighborhoodSize) -// try container.encode(base.vectors, forKey: .vectors) -// } -//} -// -//extension DeterministicEphemeralVectorIndex: Decodable where Vector: Decodable { -// public init(from decoder: Decoder) throws { -// let container = try decoder.container(keyedBy: CodingKeys.self) -// let typicalNeighborhoodSize = try container.decode(Int.self, forKey: .typicalNeighborhoodSize) -// let vectors = try container.decode([Vector].self, forKey: .vectors) -// -// self.init(typicalNeighborhoodSize: typicalNeighborhoodSize) -// for vector in vectors { -// self.insert(vector) -// } -// } -//} +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. // +// Created by Mingchung Xia on 2024-02-07. // + +import Foundation + +extension DeterministicEphemeralVectorIndex: Encodable where Vector: Encodable { + enum CodingKeys: String, CodingKey { + case typicalNeighborhoodSize + case vectors + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(typicalNeighborhoodSize, forKey: .typicalNeighborhoodSize) + try container.encode(base.vectors, forKey: .vectors) + } +} + +extension DeterministicEphemeralVectorIndex: Decodable where Vector: Decodable { + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + let typicalNeighborhoodSize = try container.decode(Int.self, forKey: .typicalNeighborhoodSize) + let vectors = try container.decode([Vector].self, forKey: .vectors) + + self.init(typicalNeighborhoodSize: typicalNeighborhoodSize) + for vector in vectors { + self.insert(vector) + } + } +} + + -- GitLab