sapling/cfastmanifest/tree_path.h
Wez Furlong 4a59f3b701 c-extensions: fixup some compiler/environment portability concerns
Summary:
I sync'd a copy of this code into the eden repository.
I had to adjust a couple of include paths to get the code to
compile correctly in the hermetic build environment that is
in use there.

In addition, our linter suite over there found a couple of C++ nits
to be fixed up.

Test Plan: make local

Reviewers: simpkins, ikostia, simonfar, durham

Reviewed By: durham

Subscribers: net-systems-diffs@fb.com, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D4879285

Signature: t1:4879285:1492039044:8cb1e033e35ee568806de94dda3d2f6f8e78f5cb
2017-04-12 16:34:53 -07:00

89 lines
2.6 KiB
C

// Copyright 2016-present Facebook. All Rights Reserved.
//
// tree_path.h: declarations for the core path function for parsing and
// traversing a path through a tree.
//
// no-check-code
#ifndef __FASTMANIFEST_TREE_PATH_H__
#define __FASTMANIFEST_TREE_PATH_H__
#include "node.h"
#include "../portability/portability.h"
typedef struct _tree_state_changes_t {
ptrdiff_t size_change;
int32_t num_leaf_node_change;
bool non_arena_allocations;
bool checksum_dirty;
} tree_state_changes_t;
typedef enum {
TREE_ADD_CHILD_OK,
TREE_ADD_CHILD_OOM,
TREE_ADD_CHILD_WTF,
} tree_add_child_code_t;
typedef struct _tree_add_child_result_t {
tree_add_child_code_t code;
node_t *newroot;
node_t *newchild;
} tree_add_child_result_t;
typedef enum {
// walks the tree and searches for a leaf node. if the path cannot be found,
// exit with `FIND_PATH_NOT_FOUND`.
BASIC_WALK,
// walks the tree and searches for any node (including implicit nodes). if
// the path cannot be found, exit with `FIND_PATH_NOT_FOUND`.
BASIC_WALK_ALLOW_IMPLICIT_NODES,
// walks the tree. if the intermediate paths cannot be found, create them.
// if a leaf node exists where an intermediate path node needs to be
// created, then return `FIND_PATH_CONFLICT`.
CREATE_IF_MISSING,
// walks the tree. if the path cannot be found, exit with
// `FIND_PATH_NOT_FOUND`. if the operation is successful, then check
// intermediate nodes to ensure that they still have children. any nodes
// that do not should be removed.
REMOVE_EMPTY_IMPLICIT_NODES,
} find_path_operation_type;
typedef enum {
FIND_PATH_OK,
FIND_PATH_NOT_FOUND,
FIND_PATH_OOM,
FIND_PATH_CONFLICT,
FIND_PATH_WTF,
} find_path_result_t;
typedef struct _find_path_callback_result_t {
find_path_result_t code;
node_t *newroot;
} find_path_callback_result_t;
extern tree_add_child_result_t tree_add_child(
tree_t *tree,
node_t *const root_parent,
node_t *root,
const char *name, const size_t name_sz,
size_t num_children_hint,
tree_state_changes_t *changes);
extern find_path_result_t find_path(
tree_t *tree,
node_t *const root_parent,
node_t *root,
const char *path, const size_t path_sz,
find_path_operation_type operation_type,
tree_state_changes_t *changes,
find_path_callback_result_t (*callback)(
tree_t *tree,
node_t *const dir_parent,
node_t *dir,
const char *path, const size_t path_sz,
tree_state_changes_t *changes,
void *context),
void *context);
#endif // #ifndef __FASTMANIFEST_TREE_PATH_H__