Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Implementing own generic hash table contains method

  1. #1
    Junior Member pyler's Avatar
    Join Date
    Sep 2012
    Posts
    23
    My Mood
    Busy
    Thanks
    3
    Thanked 2 Times in 2 Posts

    Default Implementing own generic hash table contains method

    Hi Sorry for the confusion,
    the contains method is inside a class which is basically a hash table that sorts objects of <T,N> types which are in the twos<T,N> interface.

    public class twos<T,N> implements Comparable<Pair<T,N>>{...
    public T getT(){}
    public N getN(){}
    public int compareTo(twos<T,N> something){
     
    }
    public String toString(){}
    }

    public someS<T,N> implements twos<T,N>{
    Integer cap;
    public SomeS(Integer value){cap=value;}
    twos[] someTable;
    }
    twos[] sometable;//reference
    public int myfunc(T something){
    //returns hash of something of type T}
    public boolean isEmpty(){...}
    public N get(T something){...}
    public int size(){...}
    public N remove(T something){...}
    public N add(T something,N number){...}
    public boolean contains(T param){
    return hashTable[function(param)]!=null;
    }


  2. #2
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Implementing own generic hash table contains method

    Quote Originally Posted by pyler View Post
    would it just be
    @Override
    public boolean contains(T param){
    return hashTable[function(param)]!=null;
    }
    Sorry but the context is not really clear. Where should it be this code? Are you trying to develop a custom "map" collection? Are you trying to extend/specialize one of the known map collections?
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

Similar Threads

  1. implementing generic compareTo()
    By pyler in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 5th, 2013, 05:55 AM
  2. Having trouble implementing a hash table
    By EatSleepProgram in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 1st, 2013, 03:49 AM
  3. Summing values in hash table
    By akerman in forum Java Theory & Questions
    Replies: 9
    Last Post: November 13th, 2013, 02:55 PM
  4. Replies: 4
    Last Post: November 23rd, 2012, 05:50 PM
  5. hash table probes
    By victorh in forum Collections and Generics
    Replies: 4
    Last Post: November 8th, 2011, 12:33 AM

Tags for this Thread