Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7689359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:08:53+00:00 2026-05-31T20:08:53+00:00

when scanning a file for words and using the built-in hashset class from the

  • 0

when scanning a file for words and using the built-in hashset class from the API, my word count returns 349 (which is what it’s supposed to be)

Using my home-made hashset class, I get 235… so something in my add() method must be wrong, but I can’t understand what it is.

thanks for any help!

public class HashWordSet implements WordSet {

private int size = 0;
private Node[] buckets = new Node[8];

public Iterator<Word> iterator() {
    return new WordIterator();
}

//Add word if not already added
public void add(Word word) {
    int key = getBucketNumber(word);
    Node node = buckets[key];
    while (node != null) {
        if (node.value.equals(word))
            return;
        else
            node = node.next;
    }
    node = new Node(word);
    buckets[key] = node;
    size++;
    if (size == buckets.length) rehash();
}

private int getBucketNumber(Word word) {
    int hc = word.hashCode();
    if (hc < 0) hc = -hc;
    return hc % buckets.length;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:08:54+00:00Added an answer on May 31, 2026 at 8:08 pm
    node = new Node(word);
    buckets[key] = node;
    

    If there are any nodes already in the bucket you have just thrown them away. Try something like:

    node = new Node(word);
    node.next = buckets[key];
    buckets[key] = node;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code reading a text file and scanning for words between brackets:
Using C# (VS2008) and WIA - scanning to TIFF format; When I use the
I'm trying to do barcode scanning using Android emulator. Could anyone please tell me
I am scanning a file system and wish to determine the allocated size of
I'm using following code to parse rather large xml file (> 50GB): use XML::Parser;
I'm scanning a text file that has a sudoku board with a few separators.
I have a Rails RSpec file which looks something like require 'spec_helper' describe Something
I'm using Eclipse 3.6 (Helios) with the latest Clear Case plugin from Source Forge
We have a c file called dbookpy.c, which will provide a Python binding some
Background Created a script to count the frequency of words in a plain text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.