For simplification. Lets say i have some unique values -> the numbers from 1 to 10
Now I want 1-5
map to the value "first" and I want 6-10
map to the value "second"
Is there a way I can create or extend a dictionary to work like the following?
let dict: [Range<Int> : String]
The goal is to have the following results:
print(dict[1]) // prints first
print(dict[2]) // prints first
print(dict[3]) // prints first
print(dict[7]) // prints second
print(dict[8]) // prints second
print(dict[9]) // prints second
The way I am currently doing it is to simply have the multiple keys map to the same value. But my dictionary can have sometimes 60k values. So I am wondering if a range can work.
I know I can make the value into a class
instead of a struct
so that multiple keys can map to the same class object, but I was wondering if simply creating a Dictionary that worked like above was possible?