#Hash map and Open Addressing-linear probing (java beginner)

1 messages · Page 1 of 1 (latest)

dim star
#

Hi..im supposed to create a method that removes entries using linear probing but I cant seem to get it right.
Any pointers?

public static void entryRemover(HashMap<Integer, String> map) {
            int max = Collections.max(map.entrySet(), Map.Entry.comparingByValue()).getKey();
            
            int key = 0;
            while(key <= max) {
                if(map.containsKey(key)) {
                    map.remove(key);
                }
                if(!map.containsKey(key)) {
                    key = (key + 1) % map.size();
                }
                System.out.println(key);
            }
            System.out.print("new map size:" + map.size());    
        }

https://www.geeksforgeeks.org/java-program-to-implement-hashtables-with-linear-probing/

gleaming tigerBOT
#

<@&987246399047479336> please have a look, thanks.

gleaming tigerBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

dim star
#

Hash map and linear probing(java beginner)

inner kernel
#

@dim star i cant tell if its an assignment or not, but have a look at the return type of map.remove() before u continue

dim star
#

returns 'the previous value associated with key, or null if there was no mapping for key.(A null return can also indicate that the map previously associated null with key.)'?

muted crane
#

btw, it would help if u provide more context. the exact assignment description and maybe a short description or link to "linear probing". then its much easier for people to provide help

dim star
# dim star Hi..im supposed to create a method that removes entries using linear probing bu...

sorry..i wasnt given anything else to work with but that..heres a link though https://www.geeksforgeeks.org/java-program-to-implement-hashtables-with-linear-probing/

#

Hash map and Open Addressing-linear probing (java beginner)

little comet
#

It sounds like they're expecting you to implement your own hash table

#

Rather than using the stdlib implementations