Skip to content

ganning127/augmented-hashmap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Augmented Hashmaps

A hashmap will be created that uses strings as keys, and anything (int, double, char, pointers) can be stored as a value. A self-balancing binary tree (implemented as an AVL tree) will be used as buckets, with the binary tree being sorted alphabetically based on the key.

Hashmap Documentation ./hashmap_any/hashmap.c

This hashmap works with any data type!

Hash Node Declaration

typedef struct hash_node
{
    char *key;
    int type;
    void *value;
} HNode;
typedef HNode *HNodePtr;

Tree Node Declaration

typedef struct tree_node
{
    HNodePtr data; // each node in the bst should hold a HNode
    struct tree_node *left;
    struct tree_node *right;
    size_t height;
} TreeNode;
typedef TreeNode *TreeNodePtr;

Inserting a Node

void hashmap_insert_any(ArrayListNodesPtr <list>, char *<key>, int <type>, void *<value>)

  • <list> pointer to the arraylist that represents the hashmap
  • <key> string that is used to access the value
  • <type> integer constant that specifies the type of data you want to insert (see below).
  • <value> pointer to the value you want to store

Avaliable types (users can add as necessary)

enum
{
    INT = 1,
    STRING = 2,
    DOUBLE = 3,
    CHAR = 4,
    UINT = 5,
    ULONG = 6,
};

Getting Values

HNodePtr hashmap_get(ArrayListNodesPtr list, char *key); Return type: Pointer to a hash node (see above).

  • <list> pointer to the arraylist that represents the hashmap
  • <key> string that is used to access a previously inserted value

Deleting Values

void hashmap_delete(ArrayListNodesPtr list, char *key);

  • <list> pointer to the arraylist that represents the hashmap
  • <key> string that is used to delete a previously inserted value

Example Usage

ArrayListNodesPtr list = arln_create(INITIAL_CAPACITY);
char *ins1 = "Ganning";
unsigned int ins2 = 16;

hashmap_insert_any(list, "name", STRING, ins1);
hashmap_insert_any(list, "age", UINT, &ins2);

HNodePtr res1 = hashmap_get(list, "name");
HNodePtr res2 = hashmap_get(list, "age");

displayNodeValue(res1);
displayNodeValue(res2);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published