Skip to content

How to sort keys longer than 8 bytes #4

@marekkokot

Description

@marekkokot

Hello,

I have longer keys than 8 bytes. My records are something like below:

struct Record
{
	uint64_t key[2];
	//possibly other data related to the current key
};

Is there a way to use ips2ra for such records?
I was digging into the code a little but I stuck somewhere around:

template <int level, class T>
    static inline T getBucket(const T val) {
        static_assert(sizeof(T) > level, "Too many levels");
        return (val >> (8 * (sizeof(T) - level - 1))) & 0xFF;
    }

I have defined my operator>> for Record, but according to your definition, it returns T (Record in my case).
So I suspect I would also need to define the & operator that would also return a Record, but in fact, the usable result is in fact uint8_t due to 0xFF masking.
I ended up with something like (it is a little modified from what I actually tried, not sure if the below version compiles, but I hope it shows the idea):

struct Record
{
	struct Proxy {
		uint8_t tmp;
		Record operator&(int val) const
		{
			Record res;
			res.data[0] = tmp;
			return res;
		}
		operator uint8_t()
		{
			return tmp;
		}
	};

	Proxy operator>>(const unsigned int shift) const
	{
		uint8_t* ptr = reinterpret_cast<uint8_t*>(&key);
		Proxy pr;
		pr.tmp = ptr[shift]; //this should depend on the little/big endian and if data[0] or data[1] is most significant
		return pr; 
	}
};

There may be some issues in the implementation, but I just wanted to make it compile.
Yet I have still a compile error on

yield(b, begin);

besides, I think that what I have done is a little tricky and I am afraid it may hurt performance or something.
Do you have any suggestions on how should I sort my Record?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions