This Hashable package defines a class, Hashable, for types that can be converted to a hash value. This class exists for the benefit of hashing-based data structures. The package provides instances for basic types and a way to combine hash values.
Questions tagged [hashable]
161 questions
0
votes
0 answers
Swift5 SwiftUI conforming to to Hashable causes undeclared type
I am trying to make a class "Activity" as hashable for use in swiftUI List. I followed protocol instructions for making it hashable, but when I do,I get an error later in the code that says I am using an undeclared type. This type is valid (in…

Paul Linck
- 75
- 2
- 8
0
votes
0 answers
Swift: 'Hashable.hashValue' is deprecated as a protocol requirement
I'm having this issue in my Swift project:
'Hashable.hashValue' is deprecated as a protocol requirement; conform type 'ActiveType' to 'Hashable' by implementing 'hash(into:)' instead
struct Payment: Hashable {
let product: SKProduct
let…

Alina
- 9
- 2
0
votes
1 answer
Getting "Must have a uuid if no _objectID" exception when inserting object into dictionary
I'm writing a unit-test to a class that uses PHAsset type. I mocked it as below:
class PHAssetMock: PHAsset {
let date: Date
let uuid: UUID
init(dateStr: String) {
let dateFormatter = DateFormatter()
…

Sanich
- 1,739
- 6
- 25
- 43
0
votes
4 answers
How to address specific element in list
I want to create "list of list of list". It should be:
Group (has a list of Members)
Member (has a Name and list of Properties)
Property (has Name and Value)
What I want is to have a possibility to add Property into Member (specified by its name)…

Jan Daliba
- 29
- 5
0
votes
1 answer
Does Java have something like Hashable, Hasher?
For Hash data structures, like HashSet, HashMap, etc., we need to implement hashcode. However, this is not very convenient. Can we use something like Hashable or Hasher instead?
Here is an example in…

Augie Li
- 198
- 1
- 1
- 11
0
votes
2 answers
How do I make this ForEach function work using SwiftUI?
I'm trying to follow along with this chat app tutorial and the syntax for the ForEach function has been updated in SwiftUI. Can you please help me make this list successfully compile using SwiftUI?
import SwiftUI
struct ChatMessage : Hashable {
…

Westy
- 1
- 1
0
votes
2 answers
How to remove duplicate elements of, list of dictionaries in python
I have a list of campuses:
campus = [{'id': '1', 'dlin': '1'}, {'id': '2', 'dlin': '1'},{'id': '3', 'dlin': '1'},{'id': '4', 'dlin': '2'},{'id': '5', 'dlin': '2'},{'id': '6', 'dlin': '1'}, ]
each campus belongs to a school with a unique dlin. I…

Amin Ba
- 1,603
- 1
- 13
- 38
0
votes
1 answer
How can I comprehend this sentence "two instances with the same hash value don’t necessarily compare equally. "
When I reading the book Advanced Swift and in the Chapter 'Hashable Requirement', I got confused by this explanation
two instances that are equal (as defined by your == implementation) must have the same hash value. The reverse isn’t true: two…

hsing
- 114
- 6
0
votes
4 answers
Hashable data structure with no order and allowed duplicates
I have list of tuples/lists
(-1, 0, 1)
(-1, 1, 0)
(-1, 2, -1)
(-1, -1, 2)
(0, 1, -1)
I need them to be : (-1, 1, 0)
(-1, 2, -1)
I want (-1, 0, 1) and (-1, 1, 0) map to the same thing. I thought of something like set but that would remove any…

Ajinkya Gawali
- 95
- 7
0
votes
1 answer
Complexity reduction: Find common elements in lists
Simple set-up: I have a list (roughly 40,000 entries) containing lists of strings (each with 2-15 elements). I want to compare all of the sublists to check if they have a common element (they share at most one). At the end, I want to create a…

archipelagic
- 5
- 4
0
votes
2 answers
Can't use Hashable while encoding nsarray of custom objects
I have a custom class for mapping like below.
class UserSaved {
var Id : String
var UserName : String
var profileURL : String
var fullNameUser : String
func encode(with aCoder: NSCoder) {
…

Nirav
- 157
- 12
0
votes
1 answer
Unique set of MKAnnotations
So what I'm trying to do is to update the annotations on a mapview, but I want to put them into a Set first so to check for existing, new and removed annotations. I'm having some checking for conformance of the Hashable protocol because of this…

Tommy Sadiq Hinrichsen
- 784
- 6
- 26
0
votes
1 answer
NLTK: TypeError: unhashable type: 'list'
i'm following the original code for bleu scoring as below:
from nltk.translate.bleu_score import sentence_bleu
reference = [['this', 'is', 'a', 'test'], ['this', 'is' 'test']]
candidate = ['this', 'is', 'a', 'test']
score = sentence_bleu(reference,…

Bily
- 51
- 9
0
votes
0 answers
Swift Hashable: Error unable to execute command Killed 9
I have a large data model in which the objects need to be hashable for comparision. for that I added hashValue getters to them, like this:
var hashValue:Int
{
let h1 = (31 &* id.hashValue)
&+ caseID.hashValue
&+…

BadmintonCat
- 9,416
- 14
- 78
- 129
0
votes
0 answers
What is a good hashable python dict-like object for managing configuration parameters?
In order to cache functions (right now I'm using klepto for that), I'm passing a confguration object cfg to the functions, s.t. the return value is only calculated, when cfg changes.
Therefore, cfg has to be hashable and hash(cfg1) == hash(cfg2)…

Jakob
- 1
- 2