I have a hash:
use v6;
my %some-hash = a => 0,
b => 42,
c => 417;
and I'm trying to get its keys with %some-hash.keys
, which returns a Seq of all keys but not in the order in which they were declared. It seems that the order of keys is determined at hash initialization, because it changes if I run the code several times.
Is it possible to preserve the order (a b c)
?
P.S. %some-hash.keys.sort
will not suffice, since keys are expected to have arbitrary names.
A hash key without the actual hashing applied basically: a single attribute created from the concatenation of the required attributes (including hard-coded values) and sanding delimiters. I’ve looked at it in some detail and can’t really fault it.
The hash keys also made it possible to truncate (and reload) your Dimension without having to also reload your Fact table, and to load data in essentially any order. Using hash keys has opened up our collective minds to implementing parallel loading, the ability to load data in any order and considering how to easily scale out.
For one the mapping of the hash is one-directional: from key to value, but maybe more importantly, the values are not required to be unique. In our example, both Pluto and Charon are at the same average distance from the Sun. What is more likely is that we wanted to Sort the names of the planets according to their distance form the Sun .
The java.util.Hashtable.keys() method of Hashtable class in Java is used to get the enumeration of the keys present in the hashtable. Syntax: Parameters: The method does not take any parameters. Return value: The method returns an enumeration of the keys of the Hashtable.
Hash keys are randomly ordered, as you have seen.
There are modules in the ecosystem that could help you get what you want:
Or if these don't do exactly what you want, you can build your own Hash implementation with:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With