-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort_int_node.cpp
More file actions
27 lines (22 loc) · 827 Bytes
/
sort_int_node.cpp
File metadata and controls
27 lines (22 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//
// sort_int_node.cpp
// TrieSort
//
// Created by Cameron Monks on 12/26/18.
// Copyright © 2018 Cameron Monks. All rights reserved.
//
#include "sort_int_node.hpp"
#include <iostream>
unsigned SortIntNode::hash(int index) const {
//return ((value & (1 << (maxIndex() - index))) > 0) ? 1 : 0; // one bit at a time
index = (maxIndex() - index) * 4;
int value1 = ((value & (1 << (index))) > 0) ? 1 : 0;
int value2 = ((value & (1 << (index + 1))) > 0) ? 1 : 0;
int value3 = ((value & (1 << (index + 2))) > 0) ? 1 : 0;
int value4 = ((value & (1 << (index + 3))) > 0) ? 1 : 0;
return (((((value4 << 1) + value3) << 1) + value2) << 1) + value1;
}
void SortIntNode::add(unsigned index) {
//value = (value << 1) + index; // one bit at a time
value = (value << 4) + index;
}