Code Monkey home page Code Monkey logo

dsa-c-hashtables's Introduction

Data Structures & Algorithms: [C] Hash Tables

Implementation of a hash table and related structures like set, inspired by a talk of Luciano Ramalho during PyBR2023.

Setting up

If you have cc (clang LLVM compiler) command available, just run the Makefile:

make

It will run an example by playing around with a set of weekdays.

Example of usage

The API for the set data structure is somewhat similar to Java 8 HashSet, but of course in structured programming.

And running this:

// create set
HashStrSet *weekdays_set = hashstrset_init();

// add some values to set
hashstrset_add(weekdays_set, "Monday");
hashstrset_add(weekdays_set, "Tuesday");
hashstrset_add(weekdays_set, "Wednesday");
hashstrset_add(weekdays_set, "Thursday");
hashstrset_add(weekdays_set, "Friday");
hashstrset_add(weekdays_set, "Saturday");

// remove a value from set
hashstrset_remove(weekdays_set, "Saturday");

// try to add a duplicated value to set
hashstrset_add(weekdays_set, "Monday");
hashstrset_add(weekdays_set, "Monday");
hashstrset_add(weekdays_set, "Monday");

// print set values
printf("There are %lu weekdays:\n", hashstrset_size(weekdays_set));

HashStrSetValuesIterator *iterator = hashstrset_values_iterator();
while (hashstrset_values_iterator_seek(weekdays_set, iterator))
{
    printf("- %s\n", iterator->current_value);
}
hashstrset_values_iterator_free(iterator);

// bye
hashstrset_free(weekdays_set);

Will output this:

There are 5 weekdays:
- Monday
- Friday
- Wednesday
- Tuesday
- Thursday

License

It's under the MIT License.

dsa-c-hashtables's People

Contributors

mazuh avatar

Watchers

 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.