mirror of
https://github.com/depp/syncfiles.git
synced 2024-11-24 02:31:53 +00:00
70abe95ff1
This adds a a "simple" red-black tree that can store a record of each file both on the local and remote side.
47 lines
1.0 KiB
C
47 lines
1.0 KiB
C
#ifndef sync_tree_h
|
|
#define sync_tree_h
|
|
/* tree.h - binary search trees of file metadata */
|
|
|
|
#include "sync/meta.h"
|
|
|
|
/* A reference to a file node by 1-based index, or 0 for none. */
|
|
typedef int FileRef;
|
|
|
|
typedef enum
|
|
{
|
|
kNodeBlack,
|
|
kNodeRed,
|
|
} NodeColor;
|
|
|
|
/* A file record stored in a binary search tree. */
|
|
struct FileNode {
|
|
/* The sort key. This is a case-folded version of the local filename. */
|
|
FileName key;
|
|
|
|
struct FileRec file;
|
|
|
|
/* The root of the tree for the directory contents, if this is a
|
|
directory. */
|
|
FileRef directory_root;
|
|
|
|
/* Binary search tree bookkeeping. */
|
|
NodeColor color;
|
|
FileRef children[2];
|
|
};
|
|
|
|
/* Binary search tree of files. */
|
|
struct FileTree {
|
|
struct FileNode **nodes;
|
|
Size count;
|
|
Size alloc;
|
|
FileRef root;
|
|
};
|
|
|
|
/* Insert a node into the tree with the given key. On success, return a positive
|
|
FileRef. On failure, return a negative error code. To get the error code
|
|
value, negate the function result. */
|
|
FileRef TreeInsert(struct FileTree *tree, FileRef directory,
|
|
const FileName *key);
|
|
|
|
#endif
|