<commit_before>// -*- mode:C++; tab-width:4; c-basic-offset:2; indent-tabs-mode:t -*- 
/*
 * Ceph - scalable distributed file system
 *
 * Copyright (C) 2004-2006 <NAME> <<EMAIL>>
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software 
 * Foundation.  See file COPYING.
 * 
 */


#ifndef __LOGTYPE_H
#define __LOGTYPE_H

#include "include/types.h"

#include <string>
#include <fstream>
using namespace std;
#include <ext/hash_map>
#include <ext/hash_set>
using namespace __gnu_cxx;

#include "Mutex.h"


class LogType {
 protected:
  hash_map<__uint64_t, int> keymap;  
  vector<const char*>   keys;
  set<int>              inc_keys;

  int version;

  // HACK to avoid the hash table as often as possible...
  // cache recent key name lookups in a small ring buffer
  const static int cache_keys = 10;
  __uint64_t kc_ptr[cache_keys];
  int kc_val[cache_keys];
  int kc_pos;

  friend class Logger;

 public:
  LogType() {
	version = 1;

	for (int i=0;i<cache_keys;i++)
	  kc_ptr[i] = 0;
	kc_pos = 0;
  }
  int add_key(const char* key, bool is_inc) {
	int i = lookup_key(key);
	if (i >= 0) return i;

	i = keys.size();
	keys.push_back(key);

	__uint64_t p = (__uint64_t)key;
	keymap[p] = i;
	if (is_inc) inc_keys.insert(i);

	version++;
	return i;
  }
  int add_inc(const char* key) {
	return add_key(key, true);
  }
  int add_set(const char *key) {
	return add_key(key, false);
  }
  
  bool have_key(const char* key) {
	return lookup_key(key) < 0;
  }

  int lookup_key(const char* key) {
	__uint64_t p = (__uint64_t)key;

	if (keymap.count(p)) 
	  return keymap[p];

	// try kc ringbuffer
	int pos = kc_pos-1;
	for (int j=0; j<cache_keys; j++) {
	  if (pos < 0) pos = cache_keys - 1;
	  if (kc_ptr[pos] == p) return kc_val[pos];
	  pos--;
	}

	for (unsigned i=0; i<keys.size(); i++)
	  if (strcmp(keys[i], key) == 0) {
		keymap[p] = i;<commit_msg>*** empty log message ***<commit_after>// -*- mode:C++; tab-width:4; c-basic-offset:2; indent-tabs-mode:t -*- 
/*
 * Ceph - scalable distributed file system
 *
 * Copyright (C) 2004-2006 <NAME> <<EMAIL>>
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software 
 * Foundation.  See file COPYING.
 * 
 */


#ifndef __LOGTYPE_H
#define __LOGTYPE_H

#include "include/types.h"

#include <string>
#include <fstream>
using namespace std;
#include <ext/hash_map>
#include <ext/hash_set>
using namespace __gnu_cxx;

#include "Mutex.h"


class LogType {
 protected:
  hash_map<__uint64_t, int> keymap;  
  vector<const char*>   keys;
  set<int>              inc_keys;

  int version;

  // HACK to avoid the hash table as often as possible...
  // cache recent key name lookups in a small ring buffer
  const static int cache_keys = 10;
  __uint64_t kc_ptr[cache_keys];
  int kc_val[cache_keys];
  int kc_pos;

  friend class Logger;

 public:
  LogType() {
	version = 1;

	for (int i=0;i<cache_keys;i++)
	  kc_ptr[i] = 0;
	kc_pos = 0;
  }
  int add_key(const char* key, bool is_inc) {
	int i = lookup_key(key);
	if (i >= 0) return i;

	i = keys.size();
	keys.push_back(key);

#ifdef __LP64__
	__uint64_t p = (__uint64_t)key;
#else
	__uint64_t p = (__uint32_t)key;
#endif
	keymap[p] = i;
	if (is_inc) inc_keys.insert(i);

	version++;
	return i;
  }
  int add_inc(const char* key) {
	return add_key(key, true);
  }
  int add_set(const char *key) {
	return add_key(key, false);
  }
  
  bool have_key(const char* key) {
	return lookup_key(key) < 0;
  }

  int lookup_key(const char* key) {
#ifdef __LP64__
	__uint64_t p = (__uint64_t)key;
#else
	__uint64_t p = (__uint32_t)key;
#endif

	if (keymap.count(p)) 
	  return keymap[p];

	// try kc ringbuffer
	int pos = kc_pos-1;
	for (int j=0; j<cache_keys; j++) {
	  if (pos < 0) pos = cache_keys - 1;
	  if (kc_ptr[pos] == p) return kc_val[pos];
	  pos--;
	}

	for (unsigned i=0; i<keys.size(); i++)
	  if (strcmp(keys[i], key) == 0) {
		keymap[p] = i;
{'fraction_non_alphanumeric': 0.13992172211350293, 'fraction_numerical': 0.021526418786692758, 'mean_word_length': 3.382636655948553, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 25, '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': '6920246', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1618, 'n_words': 461}