hashtable

Retrieving hashmap values in XSLT

帅比萌擦擦* 提交于 2019-12-21 19:59:57
问题 I am executing an XSLT transformation using java program. Given below is the block of code that is used for transformation. Here I am creating a hashmap and setting a value which needs to be accessed in the XSLT. TransformerFactory factory = TransformerFactory.newInstance(); StreamSource xslStream = new StreamSource(inputXSL); Transformer transformer = factory.newTransformer(xslStream); Map<String,String> mapData = new HashMap<String,String>(); mapData.put("103", "188 E 6th Street");

In-place dictionary inversion in Python

可紊 提交于 2019-12-21 17:56:54
问题 I need to invert a dictionary of lists, I don't know how to explain it in English exactly, so here is some code that does what I want. It just takes too much memory. def invert(oldDict): invertedDict = {} for key,valuelist in oldDict.iteritems(): for value in valuelist: try: entry = invertedDict[value] if key not in entry: entry.append(key) except KeyError: invertedDict[value] = [key] return invertedDict The original is a dict of lists, and the result is a dict of lists. This "inverts" it.

In-place dictionary inversion in Python

跟風遠走 提交于 2019-12-21 17:56:29
问题 I need to invert a dictionary of lists, I don't know how to explain it in English exactly, so here is some code that does what I want. It just takes too much memory. def invert(oldDict): invertedDict = {} for key,valuelist in oldDict.iteritems(): for value in valuelist: try: entry = invertedDict[value] if key not in entry: entry.append(key) except KeyError: invertedDict[value] = [key] return invertedDict The original is a dict of lists, and the result is a dict of lists. This "inverts" it.

Hashing Keys in Java

折月煮酒 提交于 2019-12-21 15:11:13
问题 In java, when I use a String as a key for Hashmap I get a little different result than when I use the string hashcode as a key in the HashMap. Any insight? 回答1: when I use the string hashcode as a key in the HashMap. You mustn't use the hash code itself as the key. Hash codes aren't intended to be unique - it's entirely permitted for two non-equal values to have the same hash code. You should use the string itself as a key. The map will then compare hash codes first (to narrow down the

Hashing Keys in Java

你说的曾经没有我的故事 提交于 2019-12-21 15:11:12
问题 In java, when I use a String as a key for Hashmap I get a little different result than when I use the string hashcode as a key in the HashMap. Any insight? 回答1: when I use the string hashcode as a key in the HashMap. You mustn't use the hash code itself as the key. Hash codes aren't intended to be unique - it's entirely permitted for two non-equal values to have the same hash code. You should use the string itself as a key. The map will then compare hash codes first (to narrow down the

How to implement a dynamic-size hash table?

北城以北 提交于 2019-12-21 10:20:21
问题 I know the basic principle of the hash table data structure. If I have a hash table of size N, I have to distribute my data into these N buckets as evenly as possible. But in reality, most languages have their built-in hash table types. When I use them, I don't need to know the size of hash table beforehand. I just put anything I want into it. For example, in Ruby : h = {} 10000000.times{ |i| h[i]=rand(10000) } How can it do this? 回答1: See the Dynamic resizing section of the Hash table

Ruby maintain Hash insertion order

冷暖自知 提交于 2019-12-21 09:20:10
问题 I am looking for a way to maintain the insert order for a Hash that I am using in Ruby. My data is coming from a database and is already grouped/ordered the way I want it, but Ruby doesn't guarantee maintained order in Hashs in my version 1.8.4 . Is there any workaround for this? If not is there a way I could create a custom comparator? Here is the Hash: { "February"=>[0.5667, 14.6834, 79.7666, 261.8668, 342.1167, 723.517], "March"=>[0.0, 26.4667, 554.45, 681.3164, 2376.0668, 10353.0358],

Salting: Is it reasonable to use the user name?

我的未来我决定 提交于 2019-12-21 08:00:17
问题 I am debating using user-names as a means to salt passwords, instead of storing a random string along with the names. My justification is that the purpose of the salt is to prevent rainbow tables, so what makes this realistically less secure than another set of data in there? For example, hash( md5(johnny_381@example.com), p4ss\/\/0rD) vs hash( md5(some_UUID_value), p4ss\/\/0rD) Is there a real reason I couldn't just stick with the user name and simplify things? The only thing my web

Hash table - implementing with Binary Search Tree

☆樱花仙子☆ 提交于 2019-12-21 05:39:10
问题 From Cracking the Coding Interview , page 71: Alternatively, we can implement hash table with a BST. We can then guarantee an O(log n) lookup time, since we can keep the tree balanced. Additionally we may use less space, since a large array no longer needs to be allocated in the very beginning. I know the basics of linked lists, hash tables and BSTs, but I am unable to understand these lines. What does it actually mean? Would this final data structure would be a Trie? 回答1: The full text of

Berkeleydb - B-Tree versus Hash Table

时光总嘲笑我的痴心妄想 提交于 2019-12-21 04:28:22
问题 I am trying to understand what should drive the choice of the access method while using a BerkeleyDB : B-Tree versus HashTable. A Hashtable provides O(1) lookup but inserts are expensive (using Linear/Extensible hashing we get amortized O(1) for insert). But B-Trees provide log N (base B) lookup and insert times. A B-Tree can also support range queries and allow access in sorted order. Apart from these considerations what else should be factored in? If I don't need to support range queries