Implement Separate-chaining Hashtable From Scratch?
Mar 19, 2014
I need to implement a separate-chaining hash table from scratch and I don't need to know the code or anything I would just like an explanation of how I would go about doing the algorithm for this perhaps pseudocode and then I can figure out the rest.
I am attempting to make a CoalescedHashMap<K, V> with internal chaining. It isn't a hard concept, but it needs to extend AbstractSet and implement Map<K, V>.
Map requires a remove method that returns a V(value). AbstractSet extends Collection, which requires a remove method that returns a boolean value. It gives a syntax error either way it is done. This is a standard homework assignment for a junior level class, so there must be some way to deal with this. It is annoying as we do not need to implement the remove method, it just throws and exception.
I don't understand, why when in the constructor of the superclass A the method init() is called (line 4), the overridden version of the subclass is invoked (line 26) and not the superclass version (line 7):
class A { public A () { init(); } public void init() { System.out.println("test");
[Code] ....
I would have guessed that above code prints
test 1
But instead you get a NPE (because when the constructor of B is invoked
public static void main(String[] args) { new B(); }
Then there is first the implicit call to super:
public B() { s = " "; init(); }
Which is the constructor of A:
public A () { init(); }
But here now this init() method is not the version of A ( public void init() { System.out.println("test"); }) but the overriden version of the subclass (B): public void init() { System.out.println(s+=s.length()); }...
Which throws an NPE of course, because the initialization of s has not occured yet (it happens only after the implicit call to super() has finished (see public B() { s = " "; init(); }))
I am having some problems with some code and I need an extra set of eyes. It appears I've missed something. I am getting a NullPointerException with a Hashtable object, which I can clearly see I've created. So I'm not quite sure why it is happening. I am pretty sure it is do with the code I've posted because I've tested everything else involved.Here is the code where it happens,
I was browsing around and I found a question asking to find how many times a word occurred in a sentence. I am using a hashtable, over kill yes but I need to use them more. However my counter is not working, not really sure why.You can see in the main method I have two repeating names but it returns 0.
package frequency; import java.util.Hashtable; public class CheckFrequency { hashtable<String, Word> words = new Hashtable<String, Word>();
I am having some difficulty adding a new item to the HashTable when a collision occurs. We can only use the basic utilities to code this, so we are coding a HashTable by hand. We have an array of length of 10, which each index holds or will hold a Node for a Linked List.
The code hashes fine, adds the item, but the problem exists when adding items that already been hashed. The project is much bigger, but this is the engine behind the rest, and I figured I would tackle this first.
The items we are adding are objects which are states containing different information, we hash based on the ASCII sum % tableSize.
Here is the code I am testing with to add items:
HashTable ht = new HashTable(10); State az = new State("Arizona","AZ","W",2,"Y",2); State fl = new State("Florida", "FL", "F", 2, "X", 2); State hi = new State("Hawaii", "HI", "H", 3, "Z", 1); State al = new State("Alabama", "AL", "A", 5, "W", 0); ht.insert(hi);
I'm writing the remove method, where you insert the key and it searches the key, if the key is found you remove the value inside the table and return that value, if they key is not found you return null. I did this method but is not returning anything in the main so I try to print inside an if to see if it was entering the condition and it appears to be looping, I'm using arrays because its an assignment
public V remove(K k) { int key = funcionHash(k); V key2 = (V) tabla[key].value; int intento=1; if(this.estatus[key]==1){ while(intento<this.tabla.length/2){ if(this.tabla[key].key.equals(k)){
I'm having a problem implementing double hashing when I insert a value into the table i get this for the output:
Insert []. Is there something I'm doing wrong? I'm not getting any errors
public static int size = 0; public static ArrayList<Integer>[] a; public static void interactiveMode(Scanner input) { int menuChoice = 0; do { System.out.println(" Interactive Mode:");
I'm having a problem with double hashing, its supposed to have the user insert an integer into the table and the integer is hashed into the table by the mod of the size of the table so say for instance table size 10 I insert 89 that inserts into 9 because 89%10=9 then i insert 18 that goes into 8 but then once i insert 69 its supposed to collide with index 9 and then uses 7-(69%7) for prime number double hashing...but it just goes into index 9 instead so in 9 it puts 89,69...there's no errors just the wrong output
System.out.print("Enter size of table: "); int n = input.nextInt(); size=n; a = new ArrayList[size]; for (int i = 0; i < size; i++) { a[i] = new ArrayList<Integer>();
How can I write a BufferredImage to an 8-bit .bmp using indexed colors stored in a <String,Color> Hashtable?
I've never used Hashtables before, and I didn't know color indexing existed until now, but I can do most other things in java fairly well.
I'm not looking for code, just the concept, as I really don't know how Hashtables work (although I could figure it out), and how color indexing does. I know how to write image files, just not indexed or with a specific number of bits. I am using Hashtables generated from GIMP.
EDIT: I mainly want to know how to save a BufferedImage as an indexed .bmp.
I have a jsp page that generate a hashtable and display its key-value pairs back to the browser. The problem is that it takes on an average about 15 minutes to build this hashtable, and as a result, I always get a timeout error. What can I do to avoid getting the timeout error without changing the server configuration for timeout
in log4j,in a web aplication i need loging in separate file,logging for action package in one file and dao in another file in action package log a class if this is possible in a class then a level in a file another level in another file.
We have this website that is run on two web applications. The first web application hosts the home page and clicking certain links in the home page would forward it to pages of the second web application where certain functionalities can be done. Now, there has been an initiative to redesign the site to have a login page and only logged in users could browse it. This would mean a login page being created in the first app, and when links to the second application are clicked, the pages are supposed to forward to it with the same session of the user that logged in.
We have already creating handling to pass the session from the first app to the second. Logging out from the first application would also invalidate the same user session in the second application. My questions is, is this a bad idea? would it be better to combine the two apps even if it would mean a huge impact?
or is there are better way to do this? like set it in web.xml. I have read that you cannot use two context for it.
my application shows a profile. The profile has various interactors. I'm trying to follow the MVC model, so I neeed to tell my controller that something was selected. But the profile has many elements that can be selected(mostly labels, so not setActionCommand), how do I tell it WHICH one was it?
how do I separate those interactors? I created a HashMap that maps from JLabels to Strings. When a mouse event occurs I loop trough it to search for the event source. If I find it I fire my custom event.
I am working on an assignment that is to simulate the relationship between a cache and main memory. Basically it is supposed to be a 16 slot cache and we are to have 500 for main memory. I need it to compare the corresponding index for both arrays, then go through then repeat the cache array and compare it to the next 16 of main memory. It is to simulate an direct mapped cache. How to compare two arrays from separate loops.
public class MainMemory { private short mainMem[] = new short[200]; public void assign(){ short i; for ( i = 0; i < mainMem.length; i ++){ mainMem[i] = i;
I am implementing the hash join algorithm for a project with a hard coded hash function. I've hashed the first relation and I've hashed the second relation. The problem is when hashing the second relation I only know how to add the tuple from the second relation into a third relation and not also access the first relation tuple at that time
The "hashtable" structure contains the hashcode of my key as well as the tuple stored in a string. This code below is taking place in the hashing of the second table, my function determines that both these tuples share the same hash code based on the first element in the tuple (element 0) so I add the tuple from my second relation to the qRelation but I also want to add the tuple from the hashtable at that point and I don't know how to access that string
if(hashtable.containsKey(tuple/*(RELATIONA)*/.get(0).hashCode())) { //Add the tuple from relation A into qRelation wich matches the //above condition qRelation.addAll(tuple/*(RELATIONB)*/); }
I am creating 2 different java codes for encryption and decryption separately based on RSA algorithm. The codes also involve swings for GUI. The problem with these codes are that my string is getting encrypted but after decrypting it,i do not get the string rather i get string of random numbers and alphabets. I am posting both the codes.
Encryption code:
import java.math.BigInteger; import java.util.Random; import java.io.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class cipher implements ActionListener
[Code] ....
Now the decryption code
import java.math.BigInteger; import java.util.Random; import java.io.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class decipher implements ActionListener
[Code] ....
The screenshots for respective codes are as attachments ....
I have created an application in SceneBuilder, and want to call a pop up (also created separately in scene builder) when a certain button is pressed. How?
I have two separate java Program that run on the same computer : Program -1 & Program-2 .
Explain Program-1 :
Name of Program -1 is “InputFrame” that is a simple frame that contain a JTextField and a Button and a JTextArea .
Explain Program 2 : Name of Program-2 is “OutputFrame” that is a simple frame that contain a simple JTextArea that this JTextArea is a Instance object from a class with name of “DisplayFrame” .
This instance object from class of “DisplayFrame” added to frame of “OutputFrame”.Now I want run both Program 1 & 2 simultaneously in the same computer and when I enter a text in JTextField in Program-1 and after click on the Button “OK” that Text Entered in this JTextField In addition to JTextArea in Program-1 display In JTextArea in Program-2 .
I do not want use a share file between two Program-1 and -2 Or DataBase .I want if Program-1 run but Program-2 is not running and i enter a text in JTextFeild in Program-1 , after running Program-2 that Entered Text Displaye in JTextArea in Frame of Program-2 .(Offline Message) .Both Source code of Program-1 and Program-2 is Attached .
I am writing a program that adds together large integers. I have to store each integer in an array of digits, with one digit per array element. Array length is 50 so integer is 50 digits long. I have to store numbers in right-shifting format with leading zeros. For example,
Sum.txt contains numbers to be added. There could be one or more numbers per line.each line must be read as string with next() since it's assumed to be a very long number. String of digits needs to be converted into an array of 50 digits. Method CharAt and Character.getNumericValue will be useful. All numbers in each line are to be added. There are no negative numbers and individual number might be 0 or answer might be 0. Answer is always 50 digits or fewer.
BigDecimal or BigInteger are not allowed.
I'm lost where it says to put number with leading zeros in a 50 room array. How do I add numbers after formatting numbers with leading zeros?