hashtable

Cannot instantiate the type Set

 ̄綄美尐妖づ 提交于 2019-11-30 21:40:03
问题 I am trying to create a Set of Strings which is filled with the keys from a Hashtable so a for-each loop can iterate through the Set and put defaults in a Hashtable. I am still learning Java but the way I am trying to do it isn't valid syntax. Could someone please demonstrate the proper way of doing this and explain why my way doesn't work and theirs does. private Hashtable<String, String> defaultConfig() { Hashtable<String, String> tbl = new Hashtable<String, String>(); tbl.put("nginx

c# Hashtable sorted by Keys

强颜欢笑 提交于 2019-11-30 20:27:13
I have a hashtable with keys in alphabetic and values in numeric. how to sort the hashtable based on keys? ExchangeA, 200 ExchangeV, 100 ExchangeC, 200 to be like this ExchangeA, 200 ExchangeC, 200 ExchangeV, 100 You can use a SortedDictionary for this which will do the sorting by key for you. In your case a SortedDictionary<string, int> would work: SortedDictionary<string, int> dict = new SortedDictionary<string, int>(); dict.Add("Exchange C", 200); dict.Add("Exchange A", 200); dict.Add("Exchange V", 100); foreach (var kvp in dict) { Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp

Java Generics: Array containing generics [duplicate]

只谈情不闲聊 提交于 2019-11-30 20:18:38
Possible Duplicate: Java how to: Generic Array creation Error generic array creation I have been tasked with writing a Hash Table in Java, which must work with any data type. The rules on the code I am writing are as follows: - The hash table must have an array as the underlying data structures, of a size determined at the time the object is constructed - When a collision occurs, the element that collides should be placed into a linked list, which holds all of the elements at that index (key) in the hash table Thus, for the underlying data type, I have made an array of type LinkedList (custom,

What exactly are hashtables?

删除回忆录丶 提交于 2019-11-30 20:17:44
What are they and how do they work? Where are they used? When should I (not) use them? I've heard the word over and over again, yet I don't know its exact meaning. What I heard is that they allow associative arrays by sending the array key through a hash function that converts it into an int and then uses a regular array. Am I right with that? (Notice: This is not my homework; I go too school but they teach us only the BASICs in informatics) Wikipedia seems to have a pretty nice answer to what they are. You should use them when you want to look up values by some index. As for when you shouldn

Iterating over a JavaScript object in sort order based on particular key value of a child object

我的梦境 提交于 2019-11-30 19:29:37
Short version: I'm looking for the JavaScript equivalent of Perl's for my $key ( sort { $hash{$a}{foo} cmp $hash{$b}{foo} } keys %hash ) { # do something with $key } More detail: I have a JSON object which consists of a bunch of other JSON objects which have identical properties to each other, like a hash of hashes in Perl: eg: var peopleobj = { "0291" : { "Forename" : "Jeremy", "Surname" : "Dyson" }, "0398" : { "Forename" : "Billy", "Surname" : "Bunter" }, "6714" : { "Forename" : "Harry", "Surname" : "Peterson" }, "9080" : { "Forename" : "Barry", "Surname" : "Mainwaring"} } I want to iterate

How would one implement a bidirectional map in Swift?

廉价感情. 提交于 2019-11-30 18:05:46
问题 I am currently in need of a performant bidirectional map. In Swift, a dictionary can be reversed, however, that will return a tuple of the types it is made of, not a counterpart dictionary. Is there a library for that or does someone have ideas on how to address this issue? Thanks 回答1: With Swift 4 you could easily make your own using a generic struct: struct BidiMap<F:Hashable,T:Hashable> { private var _forward : [F:T]? = nil private var _backward : [T:F]? = nil var forward:[F:T] { mutating

Hashtable/Dictionary collisions

你说的曾经没有我的故事 提交于 2019-11-30 17:23:27
问题 Using the standard English letters and underscore only, how many characters can be used at a maximum without causing a potential collision in a hashtable/dictionary. So strings like: blur Blur b Blur_The_Shades_Slightly_With_A_Tint_Of_Blue ... 回答1: There's no guarantee that you won't get a collision between single letters. You probably won't, but the algorithm used in string.GetHashCode isn't specified, and could change. (In particular it changed between .NET 1.1 and .NET 2.0, which burned

Find the 10 most frequently used words in a large book [duplicate]

a 夏天 提交于 2019-11-30 16:04:19
问题 This question already has answers here : Given a file, find the ten most frequently occurring words as efficiently as possible (15 answers) Closed 6 years ago . I am aware that this has been asked on the forum a couple of times, I did not find any 'TAGGED' answer which could be considered the most appropriate soluion - so asking again: We are given a very large text from book all of which cannot fit into the memory. We are required to find the top 10 most frequently occuring words in the text

Cast a hashtable.Keys into List<int> or other IEnumerable<int>

喜你入骨 提交于 2019-11-30 12:43:13
I know, I have other options, e.g. I could maintain a separate list of keys. Please don't suggest other options. I simply want to know if I can pull this off. Please don't ask me what problem I'm trying to solve, or anything like that. This is a pure and simple CS question. I want to know if anyone knows of a way to take the keys from a Hashtable and cast them into a List<int> or some other type of IEnumerable<int> (given of course that my keys are in fact integers). Given that I can do this with no problem: foreach (int key in hashtable.Keys) Why does this give me errors? (List<int>)hashtable

Which is faster to find an item in a hashtable or in a sorted list?

房东的猫 提交于 2019-11-30 11:54:21
问题 Which is faster to find an item in a hashtable or in a sorted list? 回答1: Algorithm complexity is a good thing to know, and hashtables are known to be O(1) while a sorted vector (in your case I guess it is better to use a sorted array than a list) will provide O(log n) access time. But you should know that complexity notation gives you the access time for N going to the infinite. That means that if you know that your data will keep growing , complexity notation gives you some hint on the