Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6772759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:35:11+00:00 2026-05-26T15:35:11+00:00

I want to create a hash table that relies on an independent vector data

  • 0

I want to create a hash table that relies on an independent vector data structure in C99. I can do this in C++ with the help of OO, but I’m unsure how to approach this using structs and unions.

I would prefer that any linked examples do not include hash table implementations that have highly complex hashing functions. I do not particularly care about collisions or efficiency of storage. I just want either advice as to how to proceed or a simple example that exemplifies the form rather than function of the respective data structures.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:35:12+00:00Added an answer on May 26, 2026 at 3:35 pm

    If I infer correctly that you want to implement growing hash tables in a fully generic way, then you’ll need a lot of void pointers. A vector isn’t too hard, it just takes a lot of typing:

    typedef struct {
        size_t capacity, nelems;
        void **contents;
    } Vector;
    
    enum { INITIAL_CAPACITY = 256 };
    
    Vector *make_vector()
    {
        Vector *v = malloc(sizeof(Vector));
        if (v == NULL)
            return NULL;
        v->capacity = INITIAL_CAPACITY;
        v->contents = malloc(sizeof(void *) * v->capacity);
        if (v->contents == NULL) {
            free(v);
            return NULL;
        }
        v->nelems = 0;
        return v;
    }
    
    // exercise for the reader
    int vector_append(Vector *, void *);
    void *vector_at(Vector const *);
    

    Keep in mind that a generic hash function would have prototype size_t hash(void const *, size_t), i.e. you need to pass in the size.

    (Side note: it’s not C++’s OOP features that you’re going to miss; it’s templates, the type safety that they buy, and syntactic sugar such as operator overloading. Take a look at OpenBSD’s ohash library for more examples.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to play around with C data structure (hash table). I am
Hope my question makes sense: Programming in C, can I create a hash table
I want to create a Hash Map (or another structure, if you have any
I want to create a function that performs a function passed by parameter on
I want to create a simple http proxy server that does some very basic
I want to be able to create users that have a straight up SHA-1
So I'm attempting to implement a hash table that will hash structures containing words.
I want to create a URL shortener service where you can write a long
To implement an open hash table in C++, I thought I'd define a vector
In my sql server table, I want to add a computed column that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.