Greg Roberts

Ranch Hand
+ Follow
since Feb 05, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Greg Roberts

Turns out I had forgotten to call close() on the Scanner and PrintWriters. There was still data in some buffer that had not been written to file at the end of the method, which is why it wasen't finishing the file. When I called close(), it flushed the buffer and finished writing to file.

Its always something small that I forget that causes the biggest problems.
16 years ago
I am loading a file into a scanner. The file is a text file with a listing of 88,799 names. I am reading the names and writing them out to another text file. The new text file is a list of the names along with random passwords assigned to each name.

Problem is, it stops at line 88,266. The program continues as normal, but it never completed the file. I am using a while(in.hasNext()) loop for processing the file, so the scanner should keep going until there is no more text to process. When it gets to line 88,266 it writes the name to the new file and stops, no password for that name and no more names and passwords at all.

Can anyone think of a reason for a scanner to not continue until there is no more text?
16 years ago
I posted all the requirements that I had for the hash function. I tried to get it across that I had to write a custom hash function for the project. All I got was suggestions on built-in Java functions.

Really, let's just drop it. I got a hash function working that I didn't lift from some web site. Trial and error. And got no help from anybody here.

I don't want anybody to go to any trouble and help out a student anyway.
16 years ago
I totally understand what you're saying. But I'm not in what you would call a "real" Java programming situation. I'm still a student at a university. Their intention is for us to learn a little bit about hashing. In the learning process, they want us to design our own hash function to implement our own hash table. Which is why I am seeking advice on creating a custom hash function.
16 years ago
Isn't that what this forum is for? I'd rather get advice from you guys than reading what some yahoo put on the internet. I'd rather have discussion about different functions than copy and paste from a website.

I've been to both sites and looked at what they have to offer, but I'm not supposed to use an algorithm off the internet. I'm supposed to come up with an efficient algorithm specific to this project, not generic hash algorithms somebody else came up with. I'm looking for advice on ways to come up with project-specific algorithms.
16 years ago
Does anybody here know how to implement a hash function specific like this one?
16 years ago

Originally posted by Jaap Vermeer:
How about an md5 or other standard hashing mechanism?
http://java.sun.com/j2se/1.5.0/docs/api/java/security/MessageDigest.html



We have to write our own hash function for this problem. One that will (hopefully) evenly distribute all 88,799 names across a hash table. Another problem is how big to make the hash table. The table doesn't need to be 88,799 long, because there will be linked lists to deal with collisions. I just need to figure out how big to make the table and what hash function to use to maximize efficiency.
16 years ago
Turns out we cannot use hashCode(). We have to build a hash table and hash function ourselves.
16 years ago
1. Was it a requirement not to use java.util.HashMap?

I believe we have to build our own hash table. The exact wording is "You will build an externally chained hash table of userids and passwords." He's also asking to detail how we came up with the load factor. The way this prof works, we'll have to write a custom hash table. I did just email him about it though. I'll post again as soon as I get a response.

2. Are you allowed to use String's hashCode?

We should be able to use String's hashCode.


Here's the URL for the project page:
Hashing Project
16 years ago
I need a hash function to use in a program I'm writing. I know exactly how big the table needs to be (88,799). I need to store strings in the table, with strings as the keys for those elements being stored.

Basically I'm storing a list of names and passwords associated with those names. I need to be able to enter the name in the hash table and have it return the password. Security isn't an issue because this is a school project (we have to employ some weak encryption to the passwords before they are put in the hash table anyway). I am planning on implementing an externally chained hash table, but I'm having a hard time coming up with a good hash function. I've heard its good that I know exactly how big the table will be, so I can come up with a better function.

I'm planning on using an array for the table and storing a linked list in each location to deal with collisions.

Can anyone possibly point me in the right direction?
16 years ago

Originally posted by Keith Lynn:
If you need to be able to retrieve a particular object based on an attribute or name, then you could either use an instance variable to hold the name or store the object in a HashMap.



I don't need to retrieve them later, but I do need them to be unique object references. I'm using a queue to hole a "line" of customers, and a "bay" where the customers go when it is their turn in line. Will this work, not giving the customer references unique names? They are unique in that they each have their own customer number, and I'm passing the customer into the queue or into the bay.
16 years ago
Thing is, the program will either need to create a new customer, or not, depending on events described in an input file. If it needs to create a customer, it will either place the customer in a "Work Bay", or if the Bay is full, it will drop it in a queue. I could put it in element 0 of an ArrayList, then place that element into the Bay or enqueue it in the queue, but I'll need to reference it later. What would the name of the object be?

What about this:

[ March 03, 2006: Message edited by: Greg Roberts ]
16 years ago
If you have a loop, and each iteration of the loop should create a new instance of an object, how would you tell Java to name the objects sequentially (or differently, for that matter)?

loop does this:
Customer c1 = new Customer();
Customer c2 = new Customer();
Customer c3 = new Customer();

Each iteration of the loop, how would you tell it to name them different?




This isn't actual code, just something to illustrate the question.
16 years ago
I jumped the gun on that post. I just ran a test program and it seems like a decimal is considered neither a letter or digit. It printed false when I ran isLetter and isDigit on a character '.'
17 years ago
When I call the method Character.isLetter(), and the character is a decimal '.' what will the method return? In other words, does Java consider a decimal to be a letter, a digit, or neither?
17 years ago