<commit_before>/******************************************************************************
 *  Copyright (c) 2014 <NAME> 
 *  Distributed under the MIT license 
 *  (See accompanying file LICENSE or copy at http://opensource.org/licenses/MIT)
 *  
 *  Project: Database
 *  Filename: db_fields.h 
 *  Version: 1.0
 *  Author: <NAME>
 *  E-mail: <EMAIL>
 *  Date: Oct. 23, 2014
 *  Time: 17:51:54
 *  Description: Fields of a table.
 *****************************************************************************/
#ifndef DB_FIELDS_H_
#define DB_FIELDS_H_

#include <cstring>
#include <string>
#include <vector>
#include <cassert>
#include <initializer_list>
#include "db_common.h"

class Database::DBFields {
public:
    static constexpr uint64 TYPE_INT8    = 0;
    static constexpr uint64 TYPE_UINT8   = 1;
    static constexpr uint64 TYPE_INT16   = 2;
    static constexpr uint64 TYPE_UINT16  = 3;
    static constexpr uint64 TYPE_INT32   = 4;
    static constexpr uint64 TYPE_UINT32  = 5;
    static constexpr uint64 TYPE_INT64   = 6;
    static constexpr uint64 TYPE_UINT64  = 7;
    static constexpr uint64 TYPE_BOOL    = 8;
    static constexpr uint64 TYPE_CHAR    = 9;
    static constexpr uint64 TYPE_UCHAR   = 10;
    static constexpr uint64 TYPE_FLOAT   = 11;
    static constexpr uint64 TYPE_DOUBLE  = 12;

    static constexpr uint64 FIELD_INFO_LENGTH = 256;
    static constexpr uint64 FIELD_NAME_LENGTH = 229;

    struct Comparator {
        uint64 type;
        int operator()(const void* a, const void* b, const uint64 length) {
            switch (type) {
                case 0:
                    return *pointer_convert<const int8_t*>(a) - 
                           *pointer_convert<const int8_t*>(b);
                case 1:
                    return *pointer_convert<const uint8_t*>(a) -
                           *pointer_convert<const uint8_t*>(b);
                case 2:<commit_msg>add null comparison in comparator<commit_after>/******************************************************************************
 *  Copyright (c) 2014 <NAME> 
 *  Distributed under the MIT license 
 *  (See accompanying file LICENSE or copy at http://opensource.org/licenses/MIT)
 *  
 *  Project: Database
 *  Filename: db_fields.h 
 *  Version: 1.0
 *  Author: <NAME>
 *  E-mail: <EMAIL>
 *  Date: Oct. 23, 2014
 *  Time: 17:51:54
 *  Description: Fields of a table.
 *****************************************************************************/
#ifndef DB_FIELDS_H_
#define DB_FIELDS_H_

#include <cstring>
#include <string>
#include <vector>
#include <cassert>
#include <initializer_list>
#include "db_common.h"

class Database::DBFields {
public:
    static constexpr uint64 TYPE_INT8    = 0;
    static constexpr uint64 TYPE_UINT8   = 1;
    static constexpr uint64 TYPE_INT16   = 2;
    static constexpr uint64 TYPE_UINT16  = 3;
    static constexpr uint64 TYPE_INT32   = 4;
    static constexpr uint64 TYPE_UINT32  = 5;
    static constexpr uint64 TYPE_INT64   = 6;
    static constexpr uint64 TYPE_UINT64  = 7;
    static constexpr uint64 TYPE_BOOL    = 8;
    static constexpr uint64 TYPE_CHAR    = 9;
    static constexpr uint64 TYPE_UCHAR   = 10;
    static constexpr uint64 TYPE_FLOAT   = 11;
    static constexpr uint64 TYPE_DOUBLE  = 12;

    static constexpr uint64 FIELD_INFO_LENGTH = 256;
    static constexpr uint64 FIELD_NAME_LENGTH = 229;

    struct Comparator {
        uint64 type;
        // return 0 if a == b
        // return 1 if a > b
        // return -1 if a < b
        // 1st byte of a(b) is 00 means this is null
        // null value is larger than non-null value
        // null value is equal to null
        int operator()(const void* a, const void* b, const uint64 length) {
            char a_null_flag = pointer_convert<const char*>(a)[0];
            char b_null_flag = pointer_convert<const char*>(b)[0];
            if (a_null_flag == 0x00 && b_null_flag == 0x00) return 0;
            if (a_null_flag == 0x00 && b_null_flag != 0x00) return 1;
            if (a_null_flag != 0x00 && b_null_flag == 0x00) return -1;

            switch (type) {
                case 0:
                    return *pointer_convert<const int8_t*>(a) - 
                           *pointer_convert<const int8_t*>(b);
                case 1:
                    return *pointer_convert<const uint8_t*>(a) -
                           *pointer_convert<const uint8_t*>(b);
                case 2:
{'fraction_non_alphanumeric': 0.15197294250281848, 'fraction_numerical': 0.049379932356257046, 'mean_word_length': 2.6123778501628663, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 30, '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': '3898263', 'n_tokens_mistral': 1492, 'n_tokens_neox': 1276, 'n_words': 400}