fsautoproc
Basic file transformation automation management utility
|
File index mapping and serialization implementation. More...
#include "index.h"
#include <errno.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include "log.h"
Macros | |
#define | INDEXMAXFP 512 |
The maximum filepath length of a file in the index. | |
Functions | |
static int | indexhash (const char *fp) |
Hashes the filepath string into an index bucket. | |
struct inode_s * | indexfind (const struct index_s *idx, const char *fp) |
Searches the index for a node with a matching filepath. | |
static int | indexnodecmp (const void *a, const void *b) |
Compares two file nodes for sorting in ascending order by filepath. | |
int | indexwrite (struct index_s *idx, FILE *s) |
Flattens the index map into a sorted array of nodes (by filepath). The list is then written to the file stream and freed. | |
int | indexread (struct index_s *idx, FILE *s) |
Reads a file stream and deserializes the contents into a map of individual file nodes. | |
static struct inode_s * | indexprepend (struct inode_s *idx, const struct inode_s tail) |
Prepends a new node to the linked list by overwriting the head. | |
struct inode_s * | indexput (struct index_s *idx, const struct inode_s node) |
Copies the node and inserts it into the index mapping. | |
static void | indexfree_r (struct inode_s *idx) |
Recursively frees a linked list of nodes starting from a given head. | |
void | indexfree (struct index_s *idx) |
Frees all nodes in the index map. | |
struct inode_s ** | indexlist (const struct index_s *idx) |
Flattens the index map into an unsorted array of nodes. The list is dynamically allocated and must be freed by the caller. Array size is determined by the size field in the index struct. | |
File index mapping and serialization implementation.
#define INDEXMAXFP 512 |
The maximum filepath length of a file in the index.
Searches the index for a node with a matching filepath.
idx | The index to search |
fp | The search value (filepath) to compare |
void indexfree | ( | struct index_s * | idx | ) |
Frees all nodes in the index map.
idx | The index to free |
|
static |
Recursively frees a linked list of nodes starting from a given head.
idx | The head of the linked list |
|
static |
Hashes the filepath string into an index bucket.
fp | The filepath string to hash |
Flattens the index map into an unsorted array of nodes. The list is dynamically allocated and must be freed by the caller. Array size is determined by the size
field in the index struct.
idx | The index to flatten |
idx->size
is returned. Otherwise, NULL is returned and errno
is set.
|
static |
Compares two file nodes for sorting in ascending order by filepath.
a | The first file node to compare |
b | The second file node to compare |
strcmp(a->fp, b->fp)
. Prepends a new node to the linked list by overwriting the head.
idx | The head of the linked list |
tail | The new node to prepend |
Copies the node and inserts it into the index mapping.
idx | The index to insert into |
node | The node to insert |
errno
is set. int indexread | ( | struct index_s * | idx, |
FILE * | s ) |
Reads a file stream and deserializes the contents into a map of individual file nodes.
idx | The index to populate |
s | The file stream to read from |
errno
is set. int indexwrite | ( | struct index_s * | idx, |
FILE * | s ) |
Flattens the index map into a sorted array of nodes (by filepath). The list is then written to the file stream and freed.
idx | The index to flatten |
s | The file stream to write to |
errno
is set.