hashtable

Sorting Hashtable by Order in Which It Was Created

感情迁移 提交于 2019-12-01 04:27:16
This is similar to How to keep the order of elements in hashtable , except for .NET. Is there any Hashtable or Dictionary in .NET that allows you to access it's .Index property for the entry in the order in which it was added to the collection? A NameValueCollection can retrieve elements by index (but you cannot ask for the index of a specific key or element). So, var coll = new NameValueCollection(); coll.Add("Z", "1"); coll.Add("A", "2"); Console.WriteLine("{0} = {1}", coll.GetKey(0), coll[0]); // prints "Z = 1" However, it behaves oddly (compared to an IDictionary) when you add a key

Java - Custom Hash Map/Table Some Points

荒凉一梦 提交于 2019-12-01 04:16:36
问题 In some previous posts I have asked some questions about coding of Custom Hash Map/Table in java. Now as I can't solve it and may be I forgot to properly mentioning what I really want, I am summarizing all of them to make it clear and precise. What I am going to do: I am trying to code for our server in which I have to find users access type by URL. Now, I have 1110 millions of URLs (approx). So, what we did, 1) Divided the database on 10 parts each of 110 millions of Urls. 2) Building a

Does a useful Haskell HashMap/HashTable/Dictionary library exist?

痞子三分冷 提交于 2019-12-01 03:54:01
I'm looking for a monad-free, constant access query O(1) associative array. Consider the hypothetical type: data HT k v = ??? I want to construct an immutable structure once: fromList :: Foldable t, Hashable k => t (k,v) -> HT k v I want to subsequently query it repeatedly with constant time access:: lookup :: Hashable k => HT k v -> k -> Maybe v There appears to be two candidate libraries which fall short: unordered-containers hashtables unordered-containers unordered-containers contains both strict and lazy variants of the type HashMap . Both HashMap s have O(log n) queries as documented by

Cannot instantiate the type Set

佐手、 提交于 2019-12-01 02:46:49
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-servers","/etc/nginx/servers"); tbl.put("fpm-servers","/etc/fpm/"); tbl.put("fpm-portavail","9001"); tbl.put(

Merging hashtables in PowerShell: how?

蹲街弑〆低调 提交于 2019-12-01 02:15:30
I am trying to merge two hashtables, overwriting key-value pairs in the first if the same key exists in the second. To do this I wrote this function which first removes all key-value pairs in the first hastable if the same key exists in the second hashtable. When I type this into PowerShell line by line it works. But when I run the entire function, PowerShell asks me to provide (what it considers) missing parameters to foreach-object. function mergehashtables($htold, $htnew) { $htold.getenumerator() | foreach-object { $key = $_.key if ($htnew.containskey($key)) { $htold.remove($key) } } $htnew

Hash table implementation

别来无恙 提交于 2019-12-01 01:35:44
问题 I just bought a book "C Interfaces and Implementations". in chapter one , it has implemented a "Atom" structure, sample code as follow: #define NELEMS(x) ((sizeof (x))/(sizeof ((x)[0]))) static struct atom { struct atom *link; int len; char *str; } *buckets[2048]; static unsigned long scatter[] = { 2078917053, 143302914, 1027100827, 1953210302, 755253631, 2002600785, 1405390230, 45248011, 1099951567, 433832350, 2018585307, 438263339, 813528929, 1703199216, 618906479, 573714703, 766270699,

Alternatives to 2D Arrays in Java

送分小仙女□ 提交于 2019-12-01 01:10:20
I have a lookup table that should be accessed by two separate key values. One ugly way to do this is: int[][] myArray = new int[256][256]; myArray[key1][key2] = 25; where key1 and key2 are keys that were previously generated dynamically. But this is rather ugly. It seems that a better way to do this would be to use a Map, but those require a single key, not two. Java doesn't natively support tuples, so what should I use instead? (It also seems awkward to use an array as the key). EDIT : The reason I say that this isn't particularly pretty is that my array is actually referenced by character

How would one implement a bidirectional map in Swift?

不羁岁月 提交于 2019-12-01 01:01:19
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 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 get { _forward = _forward ?? [F:T](uniqueKeysWithValues:_backward?.map{($1,$0)} ?? [] ) return _forward! }

Hashtable、synchronizedMap、ConcurrentHashMap 比较

家住魔仙堡 提交于 2019-12-01 00:49:52
Doug Lea的util.concurrent包除了包含许多其他有用的并发构造块之外,还包含了一些主要集合类型List和Map的高性能的、线程安全的实现。Brian Goetz向您展示了用ConcurrentHashMap替换Hashtable或synchronizedMap,将有多少并发程序获益。 在Java类库中出现的第一个关联的集合类是Hashtable,它是JDK 1.0的一部分。Hashtable提供了一种易于使用的、线程安全的、关联的map功能,这当然也是方便的。然而,线程安全性是凭代价换来的——Hashtable的所有方法都是同步的。 此时,无竞争的同步会导致可观的性能代价。Hashtable的后继者HashMap是作为JDK1.2中的集合框架的一部分出现的,它通过提供一个不同步的基类和一个同步的包装器Collections.synchronizedMap,解决了线程安全性问题。 通过将基本的功能从线程安全性中分离开来,Collections.synchronizedMap允许需要同步的用户可以拥有同步,而不需要同步的用户则不必为同步付出代价。 Hashtable 和 synchronizedMap所采取的获得同步的简单方法(同步Hashtable中或者同步的Map包装器对象中的每个方法)有两个主要的不足。首先,这种方法对于可伸缩性是一种障碍

Converting Matlab to Octave is there a containers.Map equivalent?

北战南征 提交于 2019-12-01 00:01:15
问题 I am trying to convert some matlab code from the Maia package into something that will work with Octave. I am currently getting stuck because one of the files has several calls to containers.Map which is apparently something that has not yet been implemented in octave. Does anyone have any ideas for easily achieving similar functionality without doing a whole lot of extra work in octave? Thanks all for your time. function [adj_direct contig_direct overlap names longest_path_direct... weigth