Skip to content

Latest commit

 

History

History
73 lines (54 loc) · 1.81 KB

README.md

File metadata and controls

73 lines (54 loc) · 1.81 KB

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.