WiscSort / wiscSort / RSW / header / utility_4.h
utility_4.h
Raw
// Compares keys and index
// indexes are ints here (r_index and v_index) -- This can cause correctness issues for large numbers
// Structures are compacted.

#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <iostream>

using std::cout;
using std::endl;

#define KEY_SIZE 10
#define P_KEY_SIZE 16
#define VALUE_SIZE 90

typedef struct k_t{
    char key[P_KEY_SIZE];
    void operator=(const k_t &rhs){;
        memcpy(&key, &rhs.key, KEY_SIZE);
    }
} k_t;

typedef struct value{
    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;

struct indexed_key{
    int r_index;
    k_t k;

    bool operator<(const indexed_key &rhs) const{
        int n;
        n = memcmp(k.key, rhs.k.key, KEY_SIZE);
        if(n>0)
            return false;
        else if (n<0)
            return true;
        else {
            return r_index < rhs.r_index;
        }
    }
    bool operator>(const indexed_key &rhs) const{
        int n;
        n = memcmp(k.key, rhs.k.key, KEY_SIZE);
        if(n>0)
            return true;
        else if (n<0)
            return false;
        else {
            return r_index > rhs.r_index;
        }
    }

    indexed_key(k_t _k, size_t _r_index){
        k = _k;
        r_index = _r_index;
    }

    indexed_key() {
        r_index = 0;
    }
//}__attribute__((packed, aligned(1)));
};

typedef struct in_record {
    indexed_key ki;
    int v_index;

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

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

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

    in_record(k_t _k, size_t _v_index, size_t _r_index) {
        ki.k = _k;
        ki.r_index = _r_index;
        v_index = _v_index;
    }

    in_record() {
        ki.r_index = 0;
        v_index = 0;
    }
//}__attribute__((packed, aligned(1))) in_record_t;
} in_record_t;

struct cacheline_three_key { size_t r_index[3]; k_t k[3]; char padding[10]; };