Questions tagged [hashable]

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.

-2
votes
0answers
34 views

([TypeError: unhashable type: 'list') but it's not

I'm trying to design a simple artificial neural network using the dataset below for human activity recognition http://www.cis.fordham.edu/wisdm/dataset.php I'm getting this error: 2019-04-16 02:21:...
0
votes
1answer
80 views

How to Implement hash(into:) from hashValue in Swift?

I don't quite have an idea on what to do with the deprecation warning from the compiler to not use hashValue and instead implement hash(into:). 'Hashable.hashValue' is deprecated as a protocol ...
1
vote
1answer
79 views

How can I update this Hashable.hashValue to conform to new requirements.?

I'm trying to fix up an old tutorial from RayWenderlich's site, no longer supported. The warning appears in three files, Chain.swift, Cookie.swift and Swap.swift from the "How to Make a Game Like ...
2
votes
1answer
43 views

NamedTuples, Hashable and Python

Consider the following code: #!/usr/bin/env python3.7 from typing import NamedTuple, Set class Person(NamedTuple): name: str fred: Set[str] p = Person("Phil", set()) print(p) my_dict = {} ...
3
votes
1answer
1k views

Swift: 'Hashable.hashValue' is deprecated as a protocol requirement;

I've been facing following issue (it's just a warning) with my iOS project. 'Hashable.hashValue' is deprecated as a protocol requirement; conform type 'ActiveType' to 'Hashable' by implementing '...
2
votes
0answers
105 views

The Hashable now want to use protocol instead of hashValue but I can't figure it out

I use to have the following code that worked in Swift 4.2 but is now deprecated in Swift 5: struct xxx: Hashable { var hashValue: Int {return uniqueIdentifier} When I try to use the new hash(...
0
votes
1answer
48 views

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 ...
-1
votes
3answers
36 views

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 ...
1
vote
1answer
51 views

Hashable == method does not detect difference between two objects swift

I implemented the class below: class Table : Hashable { var uid : Int var timeRemaining : Int? var currentPrice : Double? var hashValue: Int { return uid.hashValue } ...
0
votes
1answer
82 views

Why does struct need to conform to Hashable as well as Generic array when converting to a dictionary

The goal was to convert items in a generic list into a dictionary for the variable uniqueKeys, but I saw the error: Cannot subscript a value of incorrect or ambiguous type I knew something needed ...
0
votes
1answer
49 views

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 ...
0
votes
2answers
96 views

How to make an enum conform to Hashable with the API available in Xcode 10?

In my Swift 4.2.1 code I have this enumeration: enum MyEnum { case caseOne(Int) case caseTwo(String) case caseThree } It conforms to Equatable: extension MyEnum: Equatable { ...
0
votes
0answers
54 views

How is the hashValue generated for UIViewController in Swift 4.2

I'm wondering if I can use the hashValue of an UIViewController to uniquely identify an instance of a UIViewController during runtime. I tried to create a UIViewController and modify some of its ...
-1
votes
1answer
40 views

Generating Identification Number of String Bundle

Assume that you have a struct called bundle and it consists of string objects. There is no accurate knowledge about how many strings a bundle will contain, and you need to generate identification ...
1
vote
1answer
63 views

Set's contains method returns different value at different time

I was thinking about how Swift ensures uniqueness for Set because I have turned one of my obj from Equatable to Hashable for free and so I came up with this simple Playground struct SimpleStruct: ...
5
votes
1answer
130 views

Is this approach to dealing with hash collisions new/unique?

When dealing with hash maps, I have seen a few strategies to deal with hash collisions, but we have come up with something different. I was wondering if this is something new or not. This version of ...
0
votes
2answers
33 views

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 ...
0
votes
1answer
17 views

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 ...
0
votes
1answer
122 views

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', '...
0
votes
4answers
781 views

What is the use of hashable protocol in swift4?

please explain the use of hashable protocol with implementation in swift. Apple defines hashable as “a type that provides an integer a hash value.” Okay, but what’s a hash value?
-1
votes
1answer
71 views

Implementing Hashable and NSCoding in the same class in Swift

I am having an issue trying to adopt the Hashable and NSCoding protocols within the same Swift class (or struct). Hashability and encode/decode both work independently. However, hashability is lost ...
-2
votes
1answer
142 views

Swift : Why is it required for the key type in a Dictionary to be of type Hashable [duplicate]

If I want to create a Dictionary<Key:Value>() it is required for the Key type object to the protocol Hashable. Why is that the case, how are Dictionaries implemented? I mean I would understand ...
0
votes
0answers
51 views

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) ...
1
vote
1answer
44 views

Why is my hashable object not found in a set of that hashable object, the set being an attribute of another object?

I have a recursive relationship between objects of two classes: Foo has a set of Bar objects (in its bars attribute) and every Bar has a list of Foo objects (in its foos attribute). I've implemented ...
0
votes
0answers
43 views

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 ...
0
votes
1answer
41 views

Swift How Store And Retrieve Set Type

Accessing Set elements is fast, and Set type must to be hashable. I thought so Swift store only hashed-value of each element, but I fount the raw value (not hashed) could also be accessed. e.g like ...
1
vote
2answers
60 views

Confused with Python sets adding same object twice

If I add an integer to a Python set object twice, Python will only add it once. a = set() a.add(5) a.add(5) print(a) >> {5} However, in my app I am am trying to add coroutines to a set, ...
0
votes
2answers
60 views

Efficiently mapping unhashable objects to their index in a list

A Python list f = [x0, x1, x2] may be seen as an efficient representation of a mapping from [0, 1, ..., len(f) - 1] to the set of its elements. By "efficient" I mean that f[i] returns the element ...
0
votes
2answers
232 views

I can't understand the swift language question mark operator in dictionary in this situation transitions[prev]?[transition] [duplicate]

I've searched in a lot of places and communities among the internet to find what the heck is happening in this programing syntax. I'm seeking, desperately, for guidance in this code. What is ...
1
vote
1answer
831 views

map[gorm.DB]struct{}{} gives invalid map key type gorm.DB

I'd like to create a "set" of gorm types used in my application. So I'd like to define a map with my types gorm.DB as keys and empty structs{} as flags: var ( autoMigrations map[gorm.DB]struct{} )...
1
vote
2answers
920 views

How to make a tuple including a numpy array hashable?

One way to make a numpy array hashable is setting it to read-only. This has worked for me in the past. But when I use such a numpy array in a tuple, the whole tuple is no longer hashable, which I do ...
2
votes
2answers
451 views

Is it possible to use a Type as a dictionary key in Swift?

I’m making a Farm where everything that can be grown conforms to Growable protocol. When you plant a plant, you call this func: myFarm.planting<T: Growable>(qty: Int, of: T.Type) -> Farm ...
0
votes
1answer
102 views

It seems Swfit.AnyHashable is not casing (as!, as?, as) properly with enums

Here is a simple case example of AnyHashable not supporting casting with enums. enum testEnum: String { case Test } let myObject: AnyHashable = testEnum.Test as AnyHashable let newObject = ...
4
votes
3answers
5k views

swift 3.0 How can I access `AnyHashable` types in `Any` in Swift 3?

I'm using sqlite file to get the diaryEntriesTeacher from the authorId. it generates the following object of authorId when I print the variable authorId is nil Code :- func applySelectQuery() { ...
0
votes
1answer
376 views

Swift | Set with NSObject

I'm trying to create a Set with custom objects. This is working, If I use a Set of my custom objects there is no duplicates : public class AttributesGroup: Hashable, Equatable, Comparable { open ...
1
vote
1answer
995 views

Recommended way to implement __eq__ and __hash__

The python documentation mentions that if you override __eq__ and the object is immutable, you should also override __hash__ in order for the class to be properly hashable. In practice, when I do ...
3
votes
1answer
403 views

How does Set ensure equatability in Swift?

I'm reading Set You use a set instead of an array when you need to test efficiently for membership and you aren’t concerned with the order of the elements in the collection, or when you need to ...
0
votes
1answer
530 views

How does Swift hash Strings?

I'm looking through the Swift implementation of String (https://github.com/apple/swift/blob/master/stdlib/public/core/String.swift) String implements the Hashable protocol, which means that it must ...
15
votes
1answer
1k views

What is difference between Any , Hashable , AnyHashable in Swift 3?

I scratch my head through lots of tutorial to understand difference between above 3 terms and find new term type erased container, now it become confusing to me. It arise lots of question. Why Swift ...
0
votes
1answer
189 views

Leaflet markercluster and hashable

I have a map with a lot of markers in cluster, with the markercluster plug ( which i create thanks to a geojson in .JS file as a variable), and i'm trying to be able to dynamically modify the URL ...
3
votes
2answers
961 views

How to conform custom class with optional properties to “hashable” protocol

Suppose I have a base class "Person" that I want to add to a Set (List) and need to therefore conform to Hashable and Equatable: class Person : Equatable, Hashable { let firstName: String let ...
1
vote
1answer
540 views

How to parse this PayPal JSON response with AnyHashable value using SwiftyJSON?

I'm using PaypalSDK to add paypal payment methods to the app I'm developing, it's already working and when the payment is succesful I'm getting a response which I'm converting into a jsonObject but I ...
6
votes
3answers
10k views

Conforming to Hashable protocol?

I'm trying to make a dictionary with the key as a struct I've created and the value as an array of Ints. However, I keep getting the error: Type 'dateStruct' does not conform to protocol 'Hashable'. I'...
1
vote
2answers
640 views

Unhashable type: list

I am working on a program that parses through log files and returns the top hits for IP addresses and a couple other things. Currently I am having trouble and I cannot interpret any of the answers to ...
0
votes
1answer
611 views

Hashable protocol for a protocol

I am wondering what is wrong with the following code ? import Foundation enum SliderType: Int { case analog = 1, discrete, highLow } protocol DataEntry: class, Hashable { var hashValue: ...
0
votes
1answer
494 views

Swift 3.0 notification transformable to array or array of dictionaries?

Getting this data back as a notification and want to read it into usable variable types. I got all of them to work but the rewards and aps %@ [AnyHashable("description"): Open 10 common chests., ...
25
votes
1answer
6k views

Make struct Hashable?

I'm trying to create a dictionary of the sort [petInfo : UIImage]() but I'm getting the error Type 'petInfo' does not conform to protocol 'Hashable'. My petInfo struct is this: struct petInfo { ...
3
votes
1answer
1k views

Make simple tuple conform to Hashable, so can be a Dictionary Key

I'd like to use a very simple tuple as a key: (Int, Int) Dictionary keys need to be Hashable. I've learnt. But can't find how I make this simple tuple Hashable, and do struggle with protocol ...
-1
votes
1answer
378 views

Is it possible to generate a unique hash from a Swift closure?

Lets say we have the following struct which wraps around a closure: public struct Task: Hashable { pubic var closure: RateLimitedClosure public var hashValue: Int { // return ...
1
vote
0answers
414 views

Python - What is the fastest way to make a numpy.ndarray hashable?

Right now I'm using x.tostring() but I'm looking for something faster.

http://mssss.yulina-kosm.ru