Tagged Questions
A data structure that uses a hash function to map identifying values, known as keys, to their associated values
1
vote
3answers
86 views
+100
Android recyclerview filter
I want to optimize the below code, I have asked a similar question here.
I know this approach is better than my last code but I feel there are ways to optimize this too.This code is used in almost ...
5
votes
2answers
56 views
Increment all values in a Map by 1
What's the neatest way to increment all values in a HashMap by 1? The map is <String, Integer>, but the key doesn't matter ...
0
votes
3answers
136 views
Map class made easy for beginners to understand
I want to explain to beginners what a Map is in Java, with the assumption that beginners do not understand what a hashcode is.
As I developed games (Tarot, Belote, ...
0
votes
1answer
29 views
Quadratic probing and hashing - search for words in text files
I created a program for a college class. After I got it working, I wanted to improve it. As a beginner, it is probably a mess.
Description
It uses a HashFunction ...
2
votes
1answer
87 views
1
vote
1answer
35 views
Binary Option Pricing using Card Game
I shuffle a deck of cards(with an equal number of red and black
cards) and start dealing them face up.
After any card you can say “stop”, at which point I pay you $1 for
every red card dealt and ...
0
votes
0answers
26 views
Optimizing List creation
Using IBM JT400 toolbox, I'm reading records from a DB2 keyed table (it's like reading a ResultSet with ResultSet.next()).
As what I'm building is an higher level ...
2
votes
1answer
80 views
Data structure (Map-like implementation) in C++
I wrote this code to implement a data structure in C++. It works perfectly, however, I am looking to improve its efficiency. Also, I'm just getting started in C++ so using code to explain your ...
0
votes
0answers
46 views
Data structure that supports binary search and has near constant insertion and deletion times
I'm trying to create a data structure that has the following properties:
must be able to perform a binary search based on a on-the-fly computed value
ideally must have an \$O(1)\$ insert and delete ...
2
votes
1answer
54 views
Speed up code based on map with vectors as values
Following is the piece of code which represents the bottleneck of my application:
...
2
votes
1answer
49 views
Building and querying an immutable phone book
I wanted to get your opinion on this immutable implementation of a Phone Book using recursion to process a stream. I am especially interested in ways to speed up the code execution.
Here is an ...
5
votes
1answer
57 views
Fixed capacity unordered_map
I have a need for a container that behaves like an unordered_map, but has a fixed capacity, and an eviction policy where the least recently inserted key-value pair ...
7
votes
2answers
96 views
Hash map implementation
I'm a student in college, and while I have coded a lot, I still feel like I've only scraped the surface. I have learned a lot of things over the years, but very few of my professors ever did code ...
4
votes
1answer
45 views
Python Dictionary Manipulation
I just finished working on a coding challenge for learning Python 2.7. Essentially, I'm a function that if it is fed a string such as:
...
1
vote
2answers
88 views
Alternative to using Object and casting in a map
I have the following class which represents a set of properties.
...
2
votes
0answers
71 views
HashMap with binary search tree for chaining
My friend was asked to implement a hashtable with a binary search tree. I tried practicing it myself, and it turned out to be very verbose. I need suggestions to clean this up!
...
2
votes
3answers
65 views
Optimizing Java SHA-512 String-to-Hash Generator
In an attempt to learn Java and SHA-2 I created a very simple String-to-SHA512 generator. Here is the code:
...
2
votes
3answers
364 views
Simple Chaining Implementation of HashMap
I'm practicing writing my own simple version of a Java HashMap. I don't have much experience with generics in Java.
...
2
votes
1answer
59 views
Bare bones implementation of Java HashMap
I've done a minimal implementation of a HashMap. Invite comments.
...
4
votes
1answer
90 views
Prints Books from a HashMap that are complete or incomplete
This code is meant to display book titles that are incomplete. I have a HashMap with the book title and a number that represents the amount of the book that has ...
4
votes
1answer
281 views
Using a LinkedList type of adjacency list to create the word game: WordLadder
The user puts in a starting word and an ending word. My code creates a ladder between these words of words that are different by one letter.
Start: gain
End: fire
Output:
...
2
votes
2answers
196 views
Print max occurring character in a String
This prints the character that occurs the most in a given string.
Input: String of word(s)
Output: Max occurring character
...
3
votes
1answer
57 views
class Taboo<T> — sort passed in List<T> according to 'rules'
I know as a matter of fact that there are many areas upon which my code could be improved. I was wondering if anyone can provide me with suggestions on how Taboo ...
0
votes
3answers
316 views
Detecting if two given strings are isomorphic using Java data structures
So I have written the following code and it works for various same length isomorphic strings I have tried. However I am not sure what are some time complexity improvements and coding tweaks that could ...
0
votes
0answers
19 views
Converting from a madlib program using hashmaps to using 3 different arrays to hold the noun, verb, and adjectives
Using erb and Sinatra, I need to make an array of each variable that can be added in, [noun], [verb] and [adjective], allowing me to return the number of each there are and create the appropriate ...
5
votes
1answer
505 views
Replacing multiple substrings in a string
Here are 2 functions defined that do the exactly same thing: take input a template (in which one wants to replace some substrings) and array of strings values (key value pair to replace, such as [...
4
votes
2answers
94 views
Is this the right way to implement a simple hash table in C++?
Does this look like a proper implementation of a hash table in C++? Any errors anyone can find?
Thanks in advance (:
...
1
vote
1answer
112 views
A basic pure Python hash map using a tree
I would like feedback on my first attempt to understand how hash tables work. I've read some on how hash tables use modulo operations to find the location of a key.
Can you help me understand, ...
4
votes
1answer
115 views
Evicting an entry from a size-limited HashMap<T, Integer>
I have a HashMap with a limited size of 1000 elements. When I want to put one more, the T with the lowest related Integer in the map should be replaced with the new one.
I already have this working ...
3
votes
1answer
65 views
“Space and Time Efficient” way of finding all anagram groups
I have written a program to find all anagram groups in a text file. I used first 26 Prime numbers as a mapper for 26 characters for finding anagram groups (Since character_set of all anagrams of a ...
8
votes
2answers
692 views
Program to index a book
Indexing a book. Write a program that reads in a text file from
standard input and compiles an alphabetical index of which words
appear on which lines, as in the following input. Ignore case and
...
3
votes
2answers
279 views
Custom C++ iterator
So I have written a custom iterator for std::map that allows access to just the "values" of the map and I was wondering if it is the "correct" way to implement <...
5
votes
2answers
162 views
Registering and looking up aliases
I've taken a coding challenge as part of a job interview and the recruiting process. Sadly I didn't get through it and couldn't secure the job. I am wondering if anyone can help me out here and show ...
0
votes
3answers
108 views
Database of students
At first, I had Database to contain std::list<Student> students, but because there are over 2000 students, searching by ...
3
votes
1answer
84 views
Bidirectional map
For fun and to learn a bit, I decided to implement a bidirectional map in Ruby, relying on Ruby core libraries where possible.
Its behavior is intended to be that of a Ruby Hash, but one in which '...
2
votes
1answer
283 views
Minimal Map implementation with weak values
What follows is an implementation of the java.util.Map interface with weak values. This means that entries should be removed from the map when their values become ...
8
votes
2answers
2k views
Simple linked hash map in JS (Node/browser)
I needed a simple data structure to cache the most recent few directory contents for this project I was working on. I thought a linked hash map would be the right approach since we will cache only one ...
10
votes
2answers
2k views
Implementation of fixed size hash map
I'm trying to brush up on my algorithms and data structures and wrote a fixed sized hash map assuming both key and value will be only integers. This is a significant simplification of the real case ...
4
votes
2answers
1k views
Performance of hashmap-based session object
Unfortunately, I can't use the Tomcat session for storing the key/value pairs for each user (restricted because it's an IVR domain-based project).
But I need the same functionality like a ...
6
votes
4answers
28k views
Simple implementation of HashMap
I have implemented a HashMap which supports insertions of integer key value pairs. The approach uses an array for simplicity and uses a standard hash function. ...
11
votes
2answers
10k views
Object key-value map reversal
I have implemented functions that will let me reverse a one-to-many value 'Map', that is a plain JavaScript object.
For example,
...
5
votes
2answers
156 views
Family finances - tracking and reporting
I am looking for clean way to accumulate amounts within a input dataset. In this example, there are 18 rows of data, and the output is a 3 rows of data, accumulated by Key, by ExpenseType.
My ...
4
votes
1answer
69 views
Synchronized LinkedHashed map
I've written the following code ages ago (10+ years) which is part of a simple chat server. I'm going to refactor it a bit in Java and then for fun I'm going to convert it to Scala and use Akka actors ...
21
votes
3answers
10k views
More elegant way to increment Integers in Map?
I have a HashMap<Token, Integer>, which counts occurrences of Token. Each time Token ...
6
votes
1answer
68 views
Implementing a data structure that is a collection of sets
I'm trying to optimize my code (time optimization) based on this problem:
Let S be a set of strings. Each string in S is ...
2
votes
2answers
328 views
Counting occurrences of Char8s in a file
To learn some Data.Map and Control.Monad.State, I have written the following code, which should count the occurrences of ...
2
votes
1answer
1k views
Generic util method to convert in single map from list of array of Object generally result of JPQL/ hibernate
I have designed a generic method to convert list of array of Objects to result into single map. This is working fine, but I want to check weather a key object is valid key (whether it is overriding ...
3
votes
1answer
753 views
Trains scheduled, find max platforms per stations
Given a "folder" which contains many "files," each file contains a time-table of trains, which stations they halt on and what time, per day.
...
10
votes
1answer
1k views
Is this the right way to implement a hashmap?
Is this the right way? Any comments on the hash functions? If asked a question like this in an interview, do I need to follow all OOP concepts(because I am using Java)? Like encapsulating the ...
3
votes
1answer
510 views
Bidirectional map based on memory manipulation
This is a bidirectional map implementation that stores the values as pairs on the heap, and uses pointer arithmetic for efficient lookup.
codepad link, may be easier to read
...