<commit_before>/**
 * This file is part of the CernVM File System.
 */

#ifndef CVMFS_CATALOG_MGR_H_
#define CVMFS_CATALOG_MGR_H_

#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif

#include <inttypes.h>
#include <pthread.h>
#include <cassert>

#include <vector>
#include <map>
#include <string>

#include "catalog.h"
#include "directory_entry.h"
#include "file_chunk.h"
#include "hash.h"
#include "atomic.h"
#include "util.h"
#include "logging.h"

namespace catalog {

const unsigned kSqliteMemPerThread = 1*1024*1024;

/**
 * Lookup a directory entry including its parent entry or not.
 */
enum LookupOptions {
  kLookupSole        = 0x01,
  kLookupFull        = 0x02,
  kLookupRawSymlink  = 0x10,
};


/**
 * Results upon loading a catalog file.
 */
enum LoadError {
  kLoadNew = 0,
  kLoadUp2Date,
  kLoadNoSpace,
  kLoadFail,
};


struct Statistics {
  atomic_int64 num_lookup_inode;
  atomic_int64 num_lookup_path;
  atomic_int64 num_lookup_path_negative;
  atomic_int64 num_listing;
  atomic_int64 num_nested_listing;

  Statistics() {
    atomic_init64(&num_lookup_inode);
    atomic_init64(&num_lookup_path);
    atomic_init64(&num_lookup_path_negative);
    atomic_init64(&num_listing);
    atomic_init64(&num_nested_listing);
  }

  std::string Print() {
    return
      "lookup(inode): " + StringifyInt(atomic_read64(&num_lookup_inode)) +
      "    " +
      "lookup(path-all): " + StringifyInt(atomic_read64(&num_lookup_path)) +
      "    " +
      "lookup(path-negative): " +
        StringifyInt(atomic_read64(&num_lookup_path_negative)) +
      "    " +
      "listing: " + StringifyInt(atomic_read64(&num_listing)) +
      "    " +
      "listing nested catalogs: " +<commit_msg>add error mapping for catalog::LoadError<commit_after>/**
 * This file is part of the CernVM File System.
 */

#ifndef CVMFS_CATALOG_MGR_H_
#define CVMFS_CATALOG_MGR_H_

#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif

#include <inttypes.h>
#include <pthread.h>
#include <cassert>

#include <vector>
#include <map>
#include <string>

#include "catalog.h"
#include "directory_entry.h"
#include "file_chunk.h"
#include "hash.h"
#include "atomic.h"
#include "util.h"
#include "logging.h"

namespace catalog {

const unsigned kSqliteMemPerThread = 1*1024*1024;

/**
 * Lookup a directory entry including its parent entry or not.
 */
enum LookupOptions {
  kLookupSole        = 0x01,
  kLookupFull        = 0x02,
  kLookupRawSymlink  = 0x10,
};


/**
 * Results upon loading a catalog file.
 */
enum LoadError {
  kLoadNew = 0,
  kLoadUp2Date,
  kLoadNoSpace,
  kLoadFail,
};

inline const char* ToString(const LoadError error) {
  return (const char*[]){
    "loaded new catalog",
    "catalog was up to date",
    "not enough space to load catalog",
    "failed to load catalog"
  }[error];
}


struct Statistics {
  atomic_int64 num_lookup_inode;
  atomic_int64 num_lookup_path;
  atomic_int64 num_lookup_path_negative;
  atomic_int64 num_listing;
  atomic_int64 num_nested_listing;

  Statistics() {
    atomic_init64(&num_lookup_inode);
    atomic_init64(&num_lookup_path);
    atomic_init64(&num_lookup_path_negative);
    atomic_init64(&num_listing);
    atomic_init64(&num_nested_listing);
  }

  std::string Print() {
    return
      "lookup(inode): " + StringifyInt(atomic_read64(&num_lookup_inode)) +
      "    " +
      "lookup(path-all): " + StringifyInt(atomic_read64(&num_lookup_path)) +
      "    " +
      "lookup(path-negative): " +
        StringifyInt(atomic_read64(&num_lookup_path_negative)) +
      "    " +
      "listing: " + StringifyInt(atomic_read64(&num_listing)) +
      "    " +
      "listing nested catalogs: " +
{'fraction_non_alphanumeric': 0.11540555253130104, 'fraction_numerical': 0.0261295590636908, 'mean_word_length': 3.939516129032258, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1413962', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1300, 'n_words': 260}