Ruby – Keyword Arguments – Can you treat all of the keyword arguments as a hash? How?

Yes, this is possible, but it’s not very elegant. You’ll have to use the parameters method, which returns an array of the method’s parameters and their types (in this case we only have keyword arguments). def foo(one: 1, two: 2, three: 3) method(__method__).parameters end #=> [[:key, :one], [:key, :two], [:key, :three]] Knowing that, there’s various … Read more

Fast hash for strings

As of Python 3 this method does not work: Python has a built-in hash() function that’s very fast and perfect for most uses: >>> hash(“dfds”) 3591916071403198536 You can then make it unsigned: >>> hashu=lambda word: ctypes.c_uint64(hash(word)).value You can then turn it into a 16 byte hex string: >>> hashu(“dfds”).to_bytes(8,”big”).hex() Or an N*2 byte string, where … Read more

Why not use hashing/hash tables for everything?

Hash tables, on average, do have excellent time complexity for insertion, retrieval, and deletion. BUT: Big-O complexity isn’t everything. The constant factor is also very important. You could use hashtables in place of arrays, with the array indexes as hash keys. In either case, the time complexity of retrieving an item is O(1). But the … Read more

Have a good hash function for a C++ hash table?

Now assumming you want a hash, and want something blazing fast that would work in your case, because your strings are just 6 chars long you could use this magic: size_t precision = 2; //change the precision with this size_t hash(const char* str) { return (*(size_t*)str)>> precision; } CRC is for slowpokes 😉 Explanation: This … Read more

Hash ordering preserved between iterations if not modified?

Prior to 1.9, behavior of enumerated hashes was not in the ruby specification and therefore was up to implementation — basically, hash enumeration behavior/pattern was undefined by the language and implementations could really do whatever they want (random? sorted? insertion order? different method every time? anything goes!) 1.9+, hash enumeration is specified by the language … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)