<commit_before>// test function for increment, bulk operations

//Database functions
#include <ktremotedb.h>
#include <kclangc.h>

using namespace std;
using namespace kyototycoon;

// main routine
int main(int argc, char** argv) {

  // create the database object
  RemoteDB *rdb = new RemoteDB();

  // open the database
  if (!rdb->open("kolossus-10.kilokluster.ucsc.edu", 1978, -1)) {
    cerr << "open error: " << rdb->error().name() << endl;
  }

  rdb->clear();
  string value;
  // arbitrary expiration time
  int64_t xt = 50;

  // test integer increment function
  uint64_t key = 7;
  size_t sizeOfKey = sizeof(uint64_t);
  uint64_t initialValue = 123;
  uint64_t incrValue = 23;
  uint64_t sizeOfRecord = sizeof(uint64_t);
  size_t sp;

  char *record;
  uint64_t currValue = 0;
  
  cout << "adding record " << initialValue << " of size " << sizeOfRecord << endl;


  // Normalize a 64-bit number in the native order into the network byte order.
  // little endian (our x86 linux machine) to big Endian....
  uint64_t KCSafeIV = kyotocabinet::hton64(initialValue);

  rdb->add((char *)&key, sizeOfKey, (const char *)&KCSafeIV, sizeOfRecord);
  cerr << "add record error: " << rdb->error().name() << endl;

  record = rdb->get((char *)&key, sizeOfKey, &sp, NULL);
  currValue = kyotocabinet::ntoh64(*record);

  cout << "added record " << currValue << " of size " << sp << endl;

  KCSafeIV = kyotocabinet::hton64(incrValue);

  rdb->increment((char *)&key, sizeOfKey, KCSafeIV, xt);
  //450 (the existing record was not compatible).
  cerr << "increment error: " << rdb->error().name() << endl;
  record = rdb->get((char *)&key, sizeOfKey, &sp, NULL);

  // Denormalize a 64-bit number in the network byte order into the native order.
  // (big-endian to little endian)
  currValue = kyotocabinet::ntoh64(*record);

  printf("value after increment (should be 146): %d and size %d\n", currValue, sp);

  rdb->clear();

  // the CPP version doesn't work either
  rdb->add("1", "123");
  cerr << "add record error: " << rdb->error().name() << endl;
  rdb->increment("1", 23);
  //450 (the existing record was not compatible).
  cerr << "increment error: " << rdb->error().name() << endl;
  rdb->get("1", &value);
  cout << "key 1 incremented to (should be 146): " << value << endl;

  rdb->clear();
<commit_msg>-- got it working with Mark's help. It turns out the increment function is complete: you pass it an ordinary integer, and the API will perform the endian conversion itself. Only when performing an add do you need to do a little-endian to big-endian conversion, and then again when getting the value back:<commit_after>// test function for increment, bulk operations

//Database functions
#include <ktremotedb.h>
#include <kclangc.h>

using namespace std;
using namespace kyototycoon;

// main routine
int main(int argc, char** argv) {

  // create the database object
  RemoteDB *rdb = new RemoteDB();

  // open the database
  if (!rdb->open("kolossus-10.kilokluster.ucsc.edu", 1978, -1)) {
    cerr << "open error: " << rdb->error().name() << endl;
  }

  rdb->clear();
  string value;
  // arbitrary expiration time
  int64_t xt = 50;

  // test integer increment function
  uint64_t key = 7;
  size_t sizeOfKey = sizeof(uint64_t);
  uint64_t initialValue = 123;
  uint64_t incrValue = 23;
  uint64_t sizeOfRecord = sizeof(uint64_t);
  size_t sp;

  char *record;
  uint64_t currValue = 0;
  
  cout << "adding record " << initialValue << " of size " << sizeOfRecord << endl;


  // Normalize a 64-bit number in the native order into the network byte order.
  // little endian (our x86 linux machine) to big Endian....
  uint64_t KCSafeIV = kyotocabinet::hton64(initialValue);

  rdb->add((char *)&key, sizeOfKey, (const char *)&KCSafeIV, sizeOfRecord);
  cerr << "add record error: " << rdb->error().name() << endl;

  record = rdb->get((char *)&key, sizeOfKey, &sp, NULL);
  currValue = kyotocabinet::ntoh64(*((uint64_t*)record));

  cout << "added record " << currValue << " of size " << sp << endl;

  rdb->increment((char *)&key, sizeOfKey, incrValue, xt);
  //450 (the existing record was not compatible).
  cerr << "increment error: " << rdb->error().name() << endl;
  record = rdb->get((char *)&key, sizeOfKey, &sp, NULL);

  // Denormalize a 64-bit number in the network byte order into the native order.
  // (big-endian to little endian)
  currValue = kyotocabinet::ntoh64(*((uint64_t*)record));

  printf("value after increment (should be 146): %d and size %d\n", currValue, sp);

  rdb->clear();

  // the CPP version doesn't work either
  rdb->add("1", "123");
  cerr << "add record error: " << rdb->error().name() << endl;
  rdb->increment("1", 23);
  //450 (the existing record was not compatible).
  cerr << "increment error: " << rdb->error().name() << endl;
  rdb->get("1", &value);
  cout << "key 1 incremented to (should be 146): " << value << endl;

  rdb->clear();

{'fraction_non_alphanumeric': 0.15658725310527388, 'fraction_numerical': 0.0285074322948483, 'mean_word_length': 3.709491850431448, 'pattern_counts': {'":': 0, '<': 119, '<?xml version=': 0, '>': 39, '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': '744588', 'n_tokens_mistral': 1799, 'n_tokens_neox': 1667, 'n_words': 532}