class header files made less weird
This commit is contained in:
parent
eb72368958
commit
5b0098ad39
@ -18,3 +18,67 @@ public:
|
||||
void add(T value);
|
||||
virtual ~Autoarr2();
|
||||
};
|
||||
|
||||
|
||||
#define __AUTOARR2_MAX_BLOCK_LENGTH_DEFAULT 64
|
||||
|
||||
template<typename T>
|
||||
Autoarr2<T>::Autoarr2() {
|
||||
values=NULL;
|
||||
block_length=0;
|
||||
blocks_count=0;
|
||||
length=0;
|
||||
max_block_length=__AUTOARR2_MAX_BLOCK_LENGTH_DEFAULT;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Autoarr2<T>::Autoarr2(uint16 _max_block_length) : Autoarr2() {
|
||||
max_block_length=_max_block_length;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T *Autoarr2<T>::getptr(uint32 index) {
|
||||
if(index>=length) throw_id(ERR_WRONGINDEX);
|
||||
return values[index/max_block_length]+index%max_block_length;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T Autoarr2<T>::get(uint32 index) {
|
||||
return *getptr(index);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Autoarr2<T>::set(uint32 index, T value) {
|
||||
*getptr(index)=value;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Autoarr2<T>::add(T value) {
|
||||
if(!values){
|
||||
//values=(T**)malloc(sizeof(T*));
|
||||
values=new T*[1];
|
||||
goto create_block;
|
||||
}
|
||||
else if(block_length==max_block_length){
|
||||
block_length=0;
|
||||
create_block:
|
||||
T** new_values=new T*[blocks_count+1];
|
||||
for(uint32 i=0;i<blocks_count;i++)
|
||||
new_values[i]=values[i];
|
||||
delete[] values;
|
||||
values=new_values;
|
||||
values[blocks_count]=new T[max_block_length];
|
||||
blocks_count++;
|
||||
}
|
||||
|
||||
values[blocks_count-1][block_length]=value;
|
||||
block_length++;
|
||||
length++;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Autoarr2<T>::~Autoarr2() {
|
||||
for (uint16 i=0;i<blocks_count;i++)
|
||||
delete[] values[i];
|
||||
delete[] values;
|
||||
}
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
#include "Autoarr2_methods.hpp"
|
||||
|
||||
template class Autoarr2<uint8>;
|
||||
template class Autoarr2<int8>;
|
||||
template class Autoarr2<uint16>;
|
||||
template class Autoarr2<int16>;
|
||||
template class Autoarr2<uint32>;
|
||||
template class Autoarr2<int32>;
|
||||
template class Autoarr2<uint64>;
|
||||
template class Autoarr2<int64>;
|
||||
template class Autoarr2<float>;
|
||||
template class Autoarr2<double>;
|
||||
template class Autoarr2<Unitype>;
|
||||
@ -1,66 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Autoarr2.hpp"
|
||||
|
||||
#define __AUTOARR2_MAX_BLOCK_LENGTH_DEFAULT 64
|
||||
|
||||
template<typename T>
|
||||
Autoarr2<T>::Autoarr2() {
|
||||
values=NULL;
|
||||
block_length=0;
|
||||
blocks_count=0;
|
||||
length=0;
|
||||
max_block_length=__AUTOARR2_MAX_BLOCK_LENGTH_DEFAULT;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Autoarr2<T>::Autoarr2(uint16 _max_block_length) : Autoarr2() {
|
||||
max_block_length=_max_block_length;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T *Autoarr2<T>::getptr(uint32 index) {
|
||||
if(index>=length) throw_id(ERR_WRONGINDEX);
|
||||
return values[index/max_block_length]+index%max_block_length;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T Autoarr2<T>::get(uint32 index) {
|
||||
return *getptr(index);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Autoarr2<T>::set(uint32 index, T value) {
|
||||
*getptr(index)=value;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Autoarr2<T>::add(T value) {
|
||||
if(!values){
|
||||
//values=(T**)malloc(sizeof(T*));
|
||||
values=new T*[1];
|
||||
goto create_block;
|
||||
}
|
||||
else if(block_length==max_block_length){
|
||||
block_length=0;
|
||||
create_block:
|
||||
T** new_values=new T*[blocks_count+1];
|
||||
for(uint32 i=0;i<blocks_count;i++)
|
||||
new_values[i]=values[i];
|
||||
delete[] values;
|
||||
values=new_values;
|
||||
values[blocks_count]=new T[max_block_length];
|
||||
blocks_count++;
|
||||
}
|
||||
|
||||
values[blocks_count-1][block_length]=value;
|
||||
block_length++;
|
||||
length++;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Autoarr2<T>::~Autoarr2() {
|
||||
for (uint16 i=0;i<blocks_count;i++)
|
||||
delete[] values[i];
|
||||
delete[] values;
|
||||
}
|
||||
@ -3,17 +3,58 @@
|
||||
#include "../Hashtable/hash.h"
|
||||
#include "../Autoarr2/Autoarr2.hpp"
|
||||
|
||||
template <typename TKey, typename TValue>
|
||||
template <typename TKey, typename TVal>
|
||||
class Hashtable2{
|
||||
uint8 hein;
|
||||
public:
|
||||
Autoarr2<TKey>* keys;
|
||||
Autoarr2<TValue>* values;
|
||||
Autoarr2<TVal>* values;
|
||||
|
||||
Hashtable2();
|
||||
TValue get(TKey key);
|
||||
TValue getptr(TKey key);
|
||||
bool addOrSet(TKey key, TValue);
|
||||
TVal get(TKey key);
|
||||
TVal getptr(TKey key);
|
||||
bool addOrSet(TKey key, TVal);
|
||||
bool remove(TKey);
|
||||
virtual ~Hashtable2();
|
||||
};
|
||||
|
||||
|
||||
// amount of rows
|
||||
static const uint16 HT_HEIGHTS[]={17,61,257,1021,4099,16381,65521};
|
||||
#define HT_HEIN_MIN 0
|
||||
#define HT_HEIN_MAX 6
|
||||
|
||||
#define ARR_BC 2
|
||||
#define ARR_BL 8
|
||||
|
||||
template<typename TKey, typename TVal>
|
||||
Hashtable2<TKey, TVal>::Hashtable2() {
|
||||
hein=HT_HEIN_MIN;
|
||||
keys=new Autoarr2<TKey>;
|
||||
values=new Autoarr2<TVal>;
|
||||
}
|
||||
|
||||
template<typename TKey, typename TVal>
|
||||
TVal Hashtable2<TKey, TVal>::get(TKey key) {
|
||||
|
||||
}
|
||||
|
||||
template<typename TKey, typename TVal>
|
||||
TVal Hashtable2<TKey, TVal>::getptr(TKey key) {
|
||||
|
||||
}
|
||||
|
||||
template<typename TKey, typename TVal>
|
||||
bool Hashtable2<TKey, TVal>::addOrSet(TKey key, TVal) {
|
||||
|
||||
}
|
||||
|
||||
template<typename TKey, typename TVal>
|
||||
bool Hashtable2<TKey, TVal>::remove(TKey) {
|
||||
|
||||
}
|
||||
|
||||
template<typename TKey, typename TVal>
|
||||
Hashtable2<TKey, TVal>::~Hashtable2() {
|
||||
|
||||
}
|
||||
|
||||
@ -1,33 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Hashtable2.hpp"
|
||||
|
||||
template<typename TKey, typename TValue>
|
||||
Hashtable2<TKey, TValue>::Hashtable2() {
|
||||
|
||||
}
|
||||
|
||||
template<typename TKey, typename TValue>
|
||||
TValue Hashtable2<TKey, TValue>::get(TKey key) {
|
||||
|
||||
}
|
||||
|
||||
template<typename TKey, typename TValue>
|
||||
TValue Hashtable2<TKey, TValue>::getptr(TKey key) {
|
||||
|
||||
}
|
||||
|
||||
template<typename TKey, typename TValue>
|
||||
bool Hashtable2<TKey, TValue>::addOrSet(TKey key, TValue) {
|
||||
|
||||
}
|
||||
|
||||
template<typename TKey, typename TValue>
|
||||
bool Hashtable2<TKey, TValue>::remove(TKey) {
|
||||
|
||||
}
|
||||
|
||||
template<typename TKey, typename TValue>
|
||||
Hashtable2<TKey, TValue>::~Hashtable2() {
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user