FAQ Database Discussion Community


Merge Sorting HashTable pairs based on String key

java,sorting,hashtable
I'm writing a program that counts word occurrences in a text file and then prints them in alphabetical order. I have the counting part working correctly but I need to use a merge sort to get the words alphabetized. To that end, I wrote the following methods: public static HashPair<String,...

Why are nested dictionaries OK but nested sets forbidden?

python,dictionary,set,hashtable
Why are nested dictionaries allowed in Python, while nested sets are disallowed? One can nest dictionaries and change the sub-dictionaries on the fly, as the following demonstrates: In [1]: dict1 = {'x':{'a':1, 'b':2}, 'y':{'c':3}} In [2]: dict2 = {'x':{'a':1, 'b':2}, 'y':{'c':3}} In [3]: dict1 == dict2 Out[3]: True In [4]:...

Modifying Key in hash table?

powershell,hashtable
I was just wondering if you can modify the key in a hashtable. I have been able to successfully modify the value attached to the key but have been unable to modify the actually key. $names = @{Tree = "1"; Forest = "2"} Take for example the code above, I'd...

Is mod prime good enough as a hash function for a hashtable in C

c,hashtable,hash-function
I need a hash function that is as efficient as possible, for a hash table (actually a hash set) that uses probing (open addressing) for collision resolution. The entries stored in the table are all 4 byte ints that take on random values over the range. I am considering something...

How do you use a 'just-defined' hash value in your next hash value

ruby,hash,hashtable
If I'm creating a hash: h = { a: 5, b: a + 1 } how do I use the value of a to define a value for b in ruby syntax?...

Perl hash substitution with special characters in keys

regex,perl,hashtable,substitution,string-substitution
My current script will take an expression, ex: my $expression = '( a || b || c )'; and go through each boolean combination of inputs using sub/replace, like so: my $keys = join '|', keys %stimhash; $expression =~ s/($keys)\b/$stimhash{$1}/g; So for example expression may hold, ( 0 || 1...

foreach items in hashtable

c#,hashtable
I need to use Hastable (Not List and not Dictionary), and I have many variables with keys. I add keys and variables to class, and use it in my program. But I don't know how to parse Hashtable. I tried this: Hashtable toboofer = null; string path = @"my.bin"; FileStream...

Implementing a hash table that maps strings to an array in C++. I keep getting “Debug Assertion Failed” and I don't know why

c++,hash,hashmap,hashtable,hash-function
So as the title says I'm trying to implement a hash table that uses a hash function to map strings into an array. The hash table uses separate chaining method to handle collisions and thus requires linked list (the hash table is implemented as an array of linked lists). I...

Array Insert Time Jump

php,arrays,hashtable
During deep researching about hash and zval structure and how arrays are based on it, faced with strange insert time. Here is example: $array = array(); $someValueToInsert = 100; for ($i = 0; $i < 10000; ++$i) { $time = microtime(true); array_push($array, $someValueToInsert); echo $i . " : " ....

Why is Python's hash function treated as a sort function on some sequence of numbers?

python,python-2.7,python-3.x,hashtable
As we know, Some of Python's data structures use hash tables for storing items like set or dictionary. So there is no order in these objects. But it seems that, for some sequences of numbers that's not true. For example consider the following examples : >>> set([7,2,5,3,6]) set([2, 3, 5,...

Python Hash: Insert Method

python,hash,insert,hashtable
I have been trying to write an insert(self, key): method for my MyHashTable: class. It is supposed to use linear probing to handle collision resolution. If the key is already in the table then the method returns -2. If the key is not already in the table and there exists...

Hashing with chaining and use table of size `m`

algorithm,data-structures,hash,hashmap,hashtable
I ran into an example in Computer Science Course. suppose we use Hashing with chaining and use table of size m. the hash function map record with key k into k mod m slot. if we know the record keys is subset of {i^2 | 1 <= i <= 100},...

Use hashtable as parameter when splatting?

powershell,hashtable,start-job
I am trying to use Start-Job to launch a new Powershell script. The new script has several parameters (some optional, some not), so I want to make a hashtable and splat them. However, one of these parameters is itself a hash table. I am trying to start the job like...

Hash table with string check

c++,hashtable
I am working on some code checking the repeat of character in a string. Here is some answer I found somewhere. class Solution { public: int lengthOfLongestSubstring(string s) { int hash[256]; for(int i=0; i<256; i++) hash[i] = -1; int start = 0, ans = 0; int i; for(i=0; i<s.size(); i++){...

Find the maximum number of points that lie on the same straight line

java,algorithm,data-structures,hashtable,computational-geometry
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. This programming puzzle is taken from here on Leetcode Below is my attempt to solve it. /** * Definition for a point. * class Point { * int x; *...

Powershell V4 - Passing Hashtable to Function

powershell,hashtable
I'm writing a power shell function that will take a hashtable as one of the arguments. My questions is, Am I doing something that is bad practice? Secondly, Is their a better way of doing it? Code: function removeItem { Param([Parameter(Mandatory=$True)] [string]$path, [string]$writetoText, [email protected]{} ) } ...

Output( ) from a Set class with Singly Linked List Hash Table

java,set,hashtable,singly-linked-list
I have code that I have been working on going on 10 hours now, and for the life of me, I am unable to get the output( ) of my Set.java to work. Unfortunately I am not allowed to just import the Iterator or HashTable classes from java library. Any...

java - how to create custom hashtable iterator?

java,iterator,hashmap,hashtable,inner-classes
I am currently trying to implement a Hashtable collection--I have everything up and running but I ran into kind of a conceptual problem when I was trying to define a custom iterator for the table. I have an internal class called 'HashEntry' which are the actual objects stored in the...

Why hashTable contains redundant Keys

java,hashtable,containskey
I have a problem with Hashtable; it contains redundant keys. I have redefined the equal and the hashcode, but the same problem. below is an example of my problem. I'm really need help. Thank you in advance. public class Payoff { public ArrayList<Cluster> coalitions = new ArrayList<Cluster>(); @Override public boolean...

csv parsing and manipulation using python

python-2.7,csv,pandas,hashtable
I have a csv file which i need to parse using python. triggerid,timestamp,hw0,hw1,hw2,hw3 1,234,343,434,78,56 2,454,22,90,44,76 I need to read the file line by line, slice the triggerid,timestamp and hw3 columns from these. But the column-sequence may change from run to run. So i need to match the field name, count...

How can I use different definition of class for different template type in C++? (Class Overloading?)

c++,templates,hashtable,overloading
What I want to do is making a hash table. To make it efficient, I want it to work differently depending on the type of the data. Ex : quadratic probing method for int, separate chaining method for string. I found that I can use typeid() function to compare the...

Identifying keys with multiple values in a hash table

python,csv,hashtable
I am a beginner in Python scripting. I have a CSV file which has 5 columns and over 1000 rows. I am attaching a screenshot to give an idea of how the file looks like. (I have included only 4 rows, but the real file has over 1000 rows). So...

F#: How to identify keys that have multiple values in a HashTable?

f#,hashmap,hashtable
I am currently working on a beginner's project to implement my own duplicate file finder. This is my first time working with a .NET language, so I am still extremely unfamiliar with .NET APIs. Here is the code that I have written so far: open System open System.IO open System.Collections.Generic...

Hash Table With Chaining Search Time?

linked-list,hashtable
If I implement a hash table, I understand that the insertion is done in constant time. I also understand I can find the item in constant time if there is no collision. However, if I insert an item and chain it using a linked list in some arbitrary index and...

Why is the cost of a hash lookup O(1) when evaluating the hash function might take more time than that?

hash,hashtable,big-o,time-complexity
A HashMap (or) HashTable is an example of keyed array. Here, the indices are user-defined keys rather than the usual index number. For example, arr["first"]=99 is an example of a hashmap where theb key is first and the value is 99. Since keys are used, a hashing function is required...

Removing a node from a LinkedList (C#)

c#,data-structures,linked-list,hashtable
I created a LinkedList class with a function delete to remove a certain node from the list if found, however it's not working: public class LinkedList { public Node head; <...> public void delete(string n) { Node x = search(n); //returns the node to delete or null if not found...

Can we put hash tables inside a hash table?

java,hashtable,spreadsheet
Can we link another hash table for each key, in a hash table? My target is to have a very fast 2-d data structure to store cells in a spreadsheet. I'll store "all columns within a row" in a hash table. Then do this to all 'r' number of rows....

nim two key table with generics

generics,hashtable,nim,nimrod
Trying to create a two key dictionary in Nim where where the value is a user specified type. import Tables type TwoKeyTable[T] = Table[string, Table[string, T]] # initialize two key table proc initTwoKeyTable[T](): TwoKeyTable[T] = result = initTable[string, Table[string, T]]() # check to see if keys k1 and k2 are...

Retrieve Custom Object From Hashtable

powershell,hashtable
I've written a PowerShell function to create a custom object and stores it into a hashtable. The issue I'm facing is retrieving that object. I need to retrieve that object because it contains an array, I need to loop through that array and write it to a text file. function...

How to parse Hashtable / ArrayList [duplicate]

c#,serialization,arraylist,deserialization,hashtable
This question already has an answer here: How to unserialize PHP Serialized array/variable/class and return suitable object in C# 3 answers In the picture you can see what is in ht, but how do i parse the values from ht.. its a php serialization that i deserialize with this...

What is the use of Enumerations in Hashtables or maps?

java,hashmap,hashtable,enumeration
I was Looking for some examples of Hashtables on Stack Overflow, and found this: Enumeration enumeration = companies.elements(); while ( enumeration.hasMoreElements() ) { System.out.println("hashtable values: "+enumeration.nextElement()); } Why do we use Enumerations and specifically in Hashtables what is its significance?...

Adding a new element to an array in a hash of arrays

perl,data-structures,hashtable,associative-array,perl-data-structures
I want to read and save the content of a file in a hash of array. The first column of each row would be the key. Then, I want to read the files in a directory and add the file name to the end of the array according to the...

How to find the keys of the largest values in Hash R?

r,hash,max,hashtable
I have a hash which look likes the example and I create this hash using hash package. How can I return keys of maximum values in R ? input hash table : h<-hash( keys=c(1,4,5,6),values=c(30,25,25,30) ) # <hash> containing 3 key-value pair(s). # 1 : 30 # 4 : 25 #...

hashtable that change value by itself

java,dictionary,hashtable
I am writing a java program using HashTable and I have a hard time using it. I have a HashTable object that between initialisation and reading, the values objects change Since a piece of code is more understandable than a big paragraph, here it is : class localDictionnary { private...

Chain Hash Table: Insert function

python,hash,insert,hashtable
I have been trying to write an insert(self, key) method for my MyChainHashTable class. It is supposed to use separate chaining to handle collision resolution. If the key is not already in the hash table then it should insert the key at the end of the hashkey chained list and...

Hash tables, same record on each hash table cell

c,hashtable
There is a word dictionary in a text file. I will hash all these words. I wrote some code yet there is a problem. Last word takes place on each hash table records. main() { FILE *fp; char word[100]; char *hash[569]; int i; for(i=0;i<569;i++) hash[i]="NULL"; int m=569; int z =569;...

java, JSTL and getting values by key

java,foreach,jstl,hashtable
I would like to know why I am not able to get values from an outer hashtable using the keys in jstl, the keys are integer values, the values are inner hashtables and I am working on some legacy code hence the reason for the Hashtables, which are returned from...

Format a nested hashtable

powershell,hashtable
Given a hashtable that contains heterogeneous data such as: $items = @{ a = @{a1 = "A1"; a2 = "A2"; a3 = "A3" } b = 1234 c = @{c1 = "C1"; c2 = "C2"; c3 = "C3" } d = [DateTime]::Now } When I attempt to display the contents...

Insert key value to HashTable when value is an ArrayList

java,hashtable
I am running a for loop over some string values and I want to update the Arraylist value (for a particular key) in the pass of the loop only but when I search how to put arraylist values for a key,I can find the solution where the value is updated...

Why is the hash table resized by doubling it?

java,performance,algorithm,data-structures,hashtable
Checking in java and googling online for hashtable code examples it seems that the resizing of the table is done by doubling it. But most textbooks say that the best size for the table is a prime number. So my question is: Is the approach of doubling because: It is...

Hashtable content : the first 2 Keys are Null … How to get my saved content

java,hashtable
I have a problem with my hashtable... I have a hashtable< String1,String2 > String1 = is a JTextfield as my Hashtable Key String2 = is a JTextArea as my Hashtable content myHashtable.put(JTextfield.getText(),JTextArea.getText()); and now I want to write all my saved content from my Hashtable into a file but my...

how can I implement the constructor of a hashtable in java

java,hashmap,hashtable
Suppose I need to implement a hashtable on my own,but I have some problems about implementing my constructor. For example,if I need to initialize List[] buckets,but when I write like the following codes,the computer just gave a wrong signal of"buckets[i]=new List()" , can someone tell me how to finish the...

How do I Print a Hash Table in C?

c,hashtable,stdout
I have a program in C that creates a hash table. I want to know what it is, but I am unsure how to print it out or display it. I have pasted the program below. I am rather new to hash tables so any help would be greatly appreciated!...

Key Names With @ Symbol

rest,powershell,hashtable
I'm doing some REST API work in PowerShell, and some of the keys I need to pass to my REST API contain at symbols (@). Alternatively, some of the keys that are returned from my REST API contain at symbols (@). Is there anyway to escape this character and use...

hashtable.get not working - java

java,hashtable
The above picture shows the phone key I'm trying to retrieve from the hashtable. It's returning null where as the hash table does have that key as shown in following picture. Why is the hashtable returning null when it has the key. Please help I'm stuck from hours....

issues with trying to add an item to a linked list

c,linked-list,hashtable
I'm working with a chained hash table and trying to append an entry in case one already exists with the same hash key. But I'm running into issues. #include <stdio.h> #include <stdlib.h> #include <math.h> #define TABLE_SIZE 8 typedef struct stItem item; struct stItem { int key; item *next; }; void...

How does hopscotch hashing actually work?

algorithm,performance,hash,hashtable,hopscotch-hashing
I am reading about hopscotch hashing The algorithm says when we run into colision during insert: Otherwise, j is too far from i. To create an empty entry closer to i, find an item y whose hash value lies between i and j, but within H − 1 of j,...

Modify value when getting value of key from a hashtable in PowerShell

powershell,hashtable
In PowerShell, I have a structure (HashTable type) created like so: $Structure = @{ "KeyOne" = "Value" "KeyTwo" = "{Change.This.That}" "KeyThree" = "{Change.This.Thing} With Stuff" "Change" = @{ "This" = @{ "That" = "Another Value" "Thing" = "Yogurt" } } } The string with the curly brackets are placeholders/tokens for...

How to access actual internal factor lookup hashtable in R

r,hashtable,level,r-factor
Dear Stackoverflow community, I have looked everywhere but can't find the answer to this question. I am trying to access the factor lookup table that R uses when you change a string vector into a factor vector. I am not trying to convert a string to a factor but rather...

ostream operator<< not working properly

c++,arrays,printing,hashtable,ostream
ostream issues My ostream operator << seems not to be working or something else

Perl substitution - lookup table issue

regex,perl,hashtable,lookup,substitution
I have a ~35MB KML file where all the placemarks are named "kml1234" and the like. I want to replace the name with a readable string like "Area 9987" and I have the lookup table. I found a snippet of perl here (http://stackoverflow.com/a/6435950) and it worked for the majority of...

Nested Internal Class with Readonly Hashtable throws Null ref exception.. on assignment

c#,design-patterns,compiler-errors,hashtable,nullreferenceexception
In my internal Game class, I have both a) defined another nested internal GamerTags class and b) defined a GamerTags[] _array variable. In my internal GamerTags class (the nested class, for simplicity I left it out) I have a readonly Hashtable. After initialization, I still get a null ref exception...

Null Pointer Exception with Singly Linked List to hashtable Java

java,arraylist,set,hashtable
This is the initial class provided which we cannot modify public class SLL { public class Node { private int data; private Node next; public Node() { data = 0; next = null; } public Node(int newData, Node linkValue) { data = newData; next = linkValue; } public int getData()...

How can I send a hashtable to my clientsocket?

java,sockets,hashtable
I'm currently working on a small chat program, and for my next step I would like to send a hashtable to my clients, from my server. However, so far I was using PrintWriter out = new PrintWriter(socket.getOutputStream()); in my Server class, and Scanner in = new Scanner(socket.getInputStream()); in my Client...

How do I keep load factor small in my hash table?

data-structures,hashtable,quadratic-probing
I'm learning about hash tables and quadratic probing in particular. I've read that if the load factor is <= 0.5 and the table's size is prime, quadratic probing will always find an empty slot and no key will be accessed multiple times. It then goes on to say that, in...

Is it possible to create a Map where every Key points to the same Value?

java,hashtable
Is it possible (In Java) to create a Map where, no matter what key I was to search for, I would retrieve the same value? We can assume either a finite or infinite amount of keys. I considered a map of size 1 and load factor of 1.0, with that...

Reference as key in swift dictionary

swift,dictionary,key,hashtable,memory-address
Dictionary key requires Hashable conformance: class Test {} var dictionary = [Test: String]() // Type 'Test' dies not conform to protocol 'Hashable' class Test: NSObject {} var dictionary = [Test: String]() // Works How to get address of pure Swift class instance to use as hashValue?...

Hashtable returning null but object key is present

java,hashtable
EDIT: FML! MY implementation of hashcode had a lowercase c. -.- I've been trying to learn TDD and have been following the 'By Example' book by Kent Beck; it's very good! However, I can't seem progress because a value is returning null when I access a hashtable. I've run a...

Hashtable key syntax to refer to embedded hashtable element

powershell,hashmap,hashtable,powershell-v2.0
Assuming that I have a hashtable: $tokens = @{ Id=9999; Title="Lorem ipsum dolor sit amet"; [email protected]{Name="John Doe"; Email='[email protected]'}; [email protected]{Name="Jane Doe"; Email='[email protected]'} } And a template that I would like to populate, replacing the tokens (e.g. __Title__) with the corresponding hashtable's value: /* Author: __Author.Name__ <__Author.Email__> Analyst: __Analyst.Name__ <__Analyst.Email__> Request: __Title__...

Convert Hashtable Values In-Place

string,powershell,hashtable,powershell-v2.0
I have a hashtable with values that are a mix of int and string (sometimes string array) objects. I want to convert them all to strings, but I don't know an easy way to do this without "rebuilding" the hashtable, converting each value to a string. Is there an easier,...

Adding Strings to ArrayList> Java

java,string,list,arraylist,hashtable
I have a problem with adding String to a ArrayList>. Which is declared ArrayList<LinkedList<String>> table = new ArrayList<>(); In the constructor of the class I call ArrayLists ensureCapacity method, which doesn't seem to do what I was expecting. I was thinking it would increase the slots for LinkedList inside it,...

Holding information in hashtables or arrays then outputting

c#,checkbox,hashtable
I am developing a program in c# and am not sure what to do about this problem. In my program, I have a large amount of checkboxes (Yes and No) and when No is selected, a textbox appears prompting the user to write a comment, example below: private void checkBox48_CheckedChanged(object...

What is the runtime for quadratic probing in a HashTable?

hash,hashmap,runtime,hashtable,hashset
This is a similar question to Linear Probing Runtime but it regards quadratic probing. It makes sense to me that "Theoretical worst case is O(n)" for linear probing because in the worst case, you may have to traverse through every bucket(n buckets) What would runtime be for quadratic probing? I...

Retrieving hashmap values in XSLT

java,xslt,hashtable
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...

how to create a linked-list in a hash-table with the specific index?

java,linked-list,hashtable,collision
public boolean isCollide(String key, String value){ int index = key.hashCode(); if (this.key_array[index]==null) return false; else return true; } public void addValue(String key, String value){ Hashtable hashtable = new Hashtable(key,value); int index = key.hashCode(); if (isCollide(key,value)) { hashtable.key_array[index]=key; hashtable.value_array[index]=value; } else{ LinkedList<String> linkedList = new LinkedList<>(); linkedList.add(value); //how to create a...

Implemetning Tree with Map

java,algorithm,data-structures,hashtable,binary-tree
I have a binary tree like - 1 / \ 3 5 / \ 7 9 Now I'm trying to represent the tree using HashTable. So I have created a HashTable binaryTree - HashTable binaryTree = new HashTable<Integer, Intgeger>(); Then I am trying to add item to the binaryTree. I...

Why don't we use AVL tree for hash table's item storage?

data-structures,hashtable,avl-tree
Recently, I was looking at the hash table which is using chaining as linked list. I came to the possibility of using the "chain" as AVL tree. Therefore, each buckets in the hash table will have little AVL tree's root pointers. Wikipedia says hash table's worst case is O(n) (http://en.wikipedia.org/wiki/Hash_table)....

Add words frequency to Hashtable

java,hashtable
I'm trying to do a program that takes words from a file and put them into a Hashtable. Then I must do the frequency of the words and output like this : word , number of appearances. I know my add method it's messed up but i don't know how...

Search HashTable not by unique key

c,data-structures,hashtable,glib
I have a struct comprising a key and a trile of integers: struct MyStruct { guint32 key; guint64 field1; guint64 field2 guint64 field3; }; which I need to store into some kind of dictionarty structure. I have chosen a GHashTable (glib). MyStruct member key is unique, therfore I chose to...

Get all keys from (search.h) hash search table

c,hashtable
I'm using the search.h library to define a hash table through the hcreate function. How can I go through all the keys in that table? hsearch always expects an entry to search for (or store). This is the documentation to all the three functions that manage the hash table (...

F#: Converting tuples into a hashtable

f#,hashmap,hashtable
I am new to programming, and this is my first time working with a typed, functional, and .NET language, so pardon me if my question is silly/trivial. I have a list of tuples, and I would like to store the first item (which is a string) of each tuple as...

Very simple hash table inquisition

c,data,structure,hashtable
If the index for a hash table is calculated by using some integer value returned from a hash() function % TABLE_SIZE, doesn't that mean the only possibly index values are 0-9, since the range of the return value for the modulo operator is [0, 9]? I know this is really...

Should I cast size_t to ptrdiff_t?

c,pointers,hashtable,ptrdiff-t
I have a malloc'ed array of pointers that forms a hash table. To step through the hash table I'd use pointer arithmetic, eg: node_t ** tc = table; size_t tcs = sizeof(node_t *); for(long i = 0; i < tableSize; tc+=tcs, ++i) { // Do some stuff with *tcs location...

Optimized loading to a hashtable in C#

c#,mobile,hashtable
This is kind of an open question for knowledge. We have a file (currently CSV) which contains 800.000 strings. We parse this file after loading in with string.split. Then we put that string[] into a hashtable. We have to use a hashtable due to us wanting to find specific strings...