WiscSort / EMS / header / record.h
record.h
Raw
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include "config.h"

typedef struct k_t
{
    // std::vector<char> key(KEY_SIZE);
    char key[KEY_SIZE];

    void operator=(const k_t &rhs)
    {
        memcpy(&key, &rhs.key, KEY_SIZE);
    }
    // Initilizes key with a constant char
    void operator=(const int rhs)
    {
        for (int i = 0; i < KEY_SIZE; ++i)
            key[i] = rhs;
    }
    bool operator==(const k_t &rhs)
    {
        return memcmp(key, &rhs, KEY_SIZE) == 0;
    }
    bool operator<(const k_t &rhs) const
    {
        int n;
        n = memcmp(key, rhs.key, KEY_SIZE);
        if (n > 0)
            return false;
        else
            return true;
    }
    bool operator>(const k_t &rhs) const
    {
        int n;
        n = memcmp(key, rhs.key, KEY_SIZE);
        if (n > 0)
            return true;
        else
            return false;
    }
} k_t;

typedef struct value
{
    // std::vector<char> value(VALUE_SIZE);
    char value[VALUE_SIZE];
} value_t;

typedef struct record
{
    k_t k;
    value_t v;
    record(k_t _k, value_t _v)
    {
        k = _k;
        v = _v;
    }
    record() {}
} record_t;

// typedef struct record
// {
//     k_t k;
//     value_t v;
//     bool operator<(const record &rhs) const
//     {
//         return k < rhs.k;
//     }

//     bool operator>(const record &rhs) const
//     {
//         return k > rhs.k;
//     }

//     void operator=(const record &rhs)
//     {
//         k = rhs.k;
//         v = rhs.v;
//     }
//     record(k_t _k, value_t _v)
//     {
//         k = _k;
//         v = _v;
//     }
//     record() {}
// } record_t;

typedef struct in_record
{
    k_t k;
    size_t v_index;

    bool operator<(const in_record &rhs) const
    {
        return k < rhs.k;
    }

    bool operator>(const in_record &rhs) const
    {
        return k > rhs.k;
    }

    void operator=(const in_record &rhs)
    {
        k = rhs.k;
        v_index = rhs.v_index;
    }

    in_record(k_t _k, size_t _v_index)
    {
        k = _k;
        v_index = _v_index;
    }

    in_record() {}
} in_record_t;