include/hash_map.h

Classes

Name
struct hash Linked list for the hash_map. It contains the unmoduled hash of the board and the list of possible plays associated to this board.

Types

Name
typedef struct hash hash_t Linked list for the hash_map. It contains the unmoduled hash of the board and the list of possible plays associated to this board.

Functions

Name
uint32_t pow_u32(uint32_t x, int n)Calculate power for uint32_t type.
hash_t ** create_hash_map()Generate an empty hash_map.
uint32_t hash_board(board_t * board_t)Return the unmoduled hash of a board.
hash_t * create_linked_hash(uint32_t hashed_board, linked_plays_t * plays, hash_t * next)Initialize and fills the hash_t structure.
void merge_plays(play_t * play, play_t * new_play)Merge two plays scores in place.
void hash_map_add(hash_t ** hash_map, board_t * board, linked_plays_t * plays)Adds a board to the hash_map.
void free_plays(play_t * plays)Free play_t list.
void free_linked_plays(linked_plays_t * linked_plays)Free linked_play_t list.
void free_hash_list(hash_t * hash)Free all the hash in a hash_map entry.
void free_hash_map(hash_t ** hash_map)Free the hash_map.

Defines

Name
HASHMAP_SIZE

Types Documentation

typedef hash_t

typedef struct hash hash_t;

Linked list for the hash_map. It contains the unmoduled hash of the board and the list of possible plays associated to this board.

Functions Documentation

function pow_u32

uint32_t pow_u32(
    uint32_t x,
    int n
)

Calculate power for uint32_t type.

function create_hash_map

hash_t ** create_hash_map()

Generate an empty hash_map.

function hash_board

uint32_t hash_board(
    board_t * board_t
)

Return the unmoduled hash of a board.

function create_linked_hash

hash_t * create_linked_hash(
    uint32_t hashed_board,
    linked_plays_t * plays,
    hash_t * next
)

Initialize and fills the hash_t structure.

function merge_plays

void merge_plays(
    play_t * play,
    play_t * new_play
)

Merge two plays scores in place.

function hash_map_add

void hash_map_add(
    hash_t ** hash_map,
    board_t * board,
    linked_plays_t * plays
)

Adds a board to the hash_map.

function free_plays

void free_plays(
    play_t * plays
)

Free play_t list.

function free_linked_plays

void free_linked_plays(
    linked_plays_t * linked_plays
)

Free linked_play_t list.

function free_hash_list

void free_hash_list(
    hash_t * hash
)

Free all the hash in a hash_map entry.

function free_hash_map

void free_hash_map(
    hash_t ** hash_map
)

Free the hash_map.

Macros Documentation

define HASHMAP_SIZE

#define HASHMAP_SIZE 1000000

Source code







#ifndef hash_map_h
#define hash_map_h

#define HASHMAP_SIZE 1000000

#include <stdbool.h>
#include <stdint.h>
#include "utilities.h"
#include "init.h"

/* Struct definitions */

typedef struct hash {
    uint32_t hashed_board;
    linked_plays_t * plays;
    struct hash * next;
} hash_t;

/* Functions definitions */

uint32_t pow_u32(uint32_t x, int n);

hash_t ** create_hash_map();

uint32_t hash_board(board_t * board_t);

hash_t * create_linked_hash(uint32_t hashed_board, linked_plays_t * plays, hash_t * next);

void merge_plays(play_t * play, play_t * new_play);

void hash_map_add(hash_t ** hash_map, board_t * board, linked_plays_t * plays);

void free_plays(play_t * plays);

void free_linked_plays(linked_plays_t * linked_plays);

void free_hash_list(hash_t * hash);

void free_hash_map(hash_t ** hash_map);

#endif

Updated on 2024-06-28 at 08:11:56 +0200