Toychain!
A toy blockchain in C
|
A set of functions for the voting system. More...
#include "lib/vote.h"
#include "lib/types.h"
#include "lib/mmath.h"
#include "lib/dataio.h"
#include "lib/error.h"
#include <stdlib.h>
#include <assert.h>
Functions | |
HashCell * | create_hashcell_raw (Key *key) |
Create a hashcell raw object. Takes ownership of key. More... | |
HashCell * | create_hashcell (const Key *key) |
Create a hashcell object. Copies key. More... | |
void | free_hashcell (HashCell *hc) |
Free a HasCell object. More... | |
uint32 | hash_function (const Key *key, int size) |
Hash function for Key arrays (HashTable). More... | |
uint32 | find_position (const HashTable *t, const Key *k) |
Find the position to place k at in the HasTable t. If the position in the array is taken, find a new one using linear probing. If no position was found, returns the originally found position of hash_function(). More... | |
HashTable * | create_hashtable (const CellKey *keys, size_t size) |
Create a HashTable object containing keys elements. Keys position are found with find_position().. More... | |
void | free_hashtable (HashTable *t) |
Free a HashTable object and all the elements of the table. (Correspond to delete_hashtable in the project subject). More... | |
Key * | compute_winner (const CellProtected *decl, const CellKey *candidates, const CellKey *voters, int sizeC, int sizeV) |
Simulates an election process and returns the winner. Checks if declarations are valid and update vote numbers for each candidate. More... | |
A set of functions for the voting system.
Key * compute_winner | ( | const CellProtected * | decl, |
const CellKey * | candidates, | ||
const CellKey * | voters, | ||
int | sizeC, | ||
int | sizeV | ||
) |
Simulates an election process and returns the winner. Checks if declarations are valid and update vote numbers for each candidate.
decl | list of declaration |
cadidates | list of candidates |
voters | list of voters |
sizeC | size of candidates hashtable |
sizeV | size of voters hashtable |
Create a hashcell object. Copies key.
key |
Create a hashcell raw object. Takes ownership of key.
key |
Create a HashTable object containing keys elements. Keys position are found with find_position()..
keys | keys to store |
size | size of the table |
Find the position to place k at in the HasTable t. If the position in the array is taken, find a new one using linear probing. If no position was found, returns the originally found position of hash_function().
t | Table to store in |
k | Key to store |
void free_hashcell | ( | HashCell * | hc | ) |
Free a HasCell object.
hc | Object to free. |
void free_hashtable | ( | HashTable * | t | ) |
Free a HashTable object and all the elements of the table. (Correspond to delete_hashtable in the project subject).
t | object to free |