GithubHelp home page GithubHelp logo

kraussj / my-hashset Goto Github PK

View Code? Open in Web Editor NEW

This project forked from turncodr/my-hashset

0.0 0.0 0.0 66 KB

A simple implementation of a HashSet using separate chaining with linked lists

License: MIT License

Java 100.00%

my-hashset's Introduction

my-hashset

A simple implementation of a HashSet using separate chaining with linked lists

Challenge

Implement an efficient Iterator for the class HashSet. HashSet implements Iterable, hence, you have to implement the iterator() method of the class. The class already contains a stub for this method.

The requirements of an Iterator are formulated in the Javadoc of the Iterator interface: https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html

What does 'efficient' mean in this context?

  • Running time: The internal data structure is an ArrayList of LinkedLists. It is in the nature of hashing that the internal structure is sparse. That means only few positions in the ArrayList really contain a LinkedList with hopefully only very few (ideal: only one) elements. Before an iteration, we don't no these positions, i.e. we have to check each position of the ArrayList sequentially until we find a next element. Therefore, an iteration of the HashSet is efficient if each place in the structure is visited only once!
  • Space: We want to be efficient concerning usage of memory, too. That means, we want to avoid copying elements or lists of the internal structure. Nevertheless, it is definitely necessary to store the current state of the iteration in the Iterator object (how can this be done best?), since there might be some time between subsequent calls to the next() method. Be careful, the hasNext() method should not change this state, since it can be called several times without calling the next() method.
  • BTW, our HashSet class guarantees no order for the iteration (e.g. insertion order or natural order)!
  • Currently, I skipped the remove() method of the iterator to reduce complexity. So in a first draft I am happy with a read only iterator. If you are bored by that, don't hesitate to implement the remove() method as well.

Git Workflow

Before you start:

  • Fork the repository.
  • Clone your fork and set my repo as upstream remote.
  • Implement your Iterator in a new branch.
  • If you have finished create a Pull-Request.

Following these rules will help me to compare your solutions easily (and to integrate the best one in the master branch:-))

Getting started

The repository contains a gradle project. You can build it best by using the contained gradle wrapper:

  • Linux/macOS> ./gradlew build
  • Windows> gradlew.bat build

Feel free to use the power of the other gradle tasks (like e.g. test) as well. The project contains only two Java classes. The class HashSet and the corresponding test class HashSetTest. If you start the gradle build task everything is compiled and the test are executed. Since the implementation of the Iterator is missing, the respective test method fails. In the build folder you'll find a nice html page presenting the test results. After your implementation the tests should be green.

Finally

I hope that I did not make to many bugs! ;-) Have fun!

my-hashset's People

Contributors

schmolli avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.