0% found this document useful (0 votes)
33 views1 page

Computer Science Fundamentals

This document provides examples of how to perform common operations on hash tables using the uthash library in C. It explains that uthash.h is included by default and provides examples for adding an item to a hash table by specifying the key field, looking up an item by its key, and deleting an item from the hash table.

Uploaded by

Rajay Gordon
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
0% found this document useful (0 votes)
33 views1 page

Computer Science Fundamentals

This document provides examples of how to perform common operations on hash tables using the uthash library in C. It explains that uthash.h is included by default and provides examples for adding an item to a hash table by specifying the key field, looking up an item by its key, and deleting an item from the hash table.

Uploaded by

Rajay Gordon
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 1

Computing is the act of the computer taking an input, processing it, and giving an

output.

A memory register is a single block of memory in memory, that stores data.

Data structures are the process of sorting and storing data efficiently in memory.

Algorithm is the process of finding the best way to instruct the data to do what it
needs to, in the best way possible by setting up a sequence of
accurate instructions.

A decision tree is a sequence of yes/no questions that help the computer decide
what to output.

A program is a set of instructions for the computer to execute.

Programs are limited by the commands available.

Repetition is a powerful tool in computer science that lets you write programs that
can make use of limited space.

========================
DATA STRUCTURES for C
=========================
For hash table operations, you may use uthash. "uthash.h" is included by default.
Below are some examples:

1. Adding an item to a hash.

struct hash_entry {
int id; /* we'll use this field as the key */
char name[10];
UT_hash_handle hh; /* makes this structure hashable */
};

struct hash_entry *users = NULL;

void add_user(struct hash_entry *s) {


HASH_ADD_INT(users, id, s);
}
2. Looking up an item in a hash:

struct hash_entry *find_user(int user_id) {


struct hash_entry *s;
HASH_FIND_INT(users, &user_id, s);
return s;
}
3. Deleting an item in a hash:

void delete_user(struct hash_entry *user) {


HASH_DEL(users, user);
}

You might also like