Autoarr2 works now

This commit is contained in:
2022-06-02 20:33:13 +03:00
parent cb64df9218
commit 281befa1d7
13 changed files with 115 additions and 56 deletions

View File

@@ -1,21 +1,24 @@
//
//
//
#pragma once
#include "../base/base.h"
template <typename T>
class Autoarr2 {
public:
T** values;
uint16 blocks_count;
uint16 block_length;
uint16 max_block_length;
public:
uint32 Length;
uint32 length;
Autoarr2();
explicit Autoarr2(uint16 _max_block_length);
T* GetPtr(uint32 index);
T Get(uint32 index);
void Set(uint32 index, T value);
void Add(T value);
~Autoarr2();
T* getptr(uint32 index);
T get(uint32 index);
void set(uint32 index, T value);
void add(T value);
virtual ~Autoarr2();
};

View File

@@ -0,0 +1,13 @@
#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>;

View File

@@ -1,57 +1,57 @@
//
//
//
#pragma once
#include "Autoarr2.hpp"
#define MAX_BLOCK_LENGTH_DEFAULT 64
#define __AUTOARR2_MAX_BLOCK_LENGTH_DEFAULT 64
template<typename T>
Autoarr2<T>::Autoarr2() {
values=NULL;
block_length=0;
blocks_count=0;
max_block_length=MAX_BLOCK_LENGTH_DEFAULT;
length=0;
max_block_length=__AUTOARR2_MAX_BLOCK_LENGTH_DEFAULT;
}
template<typename T>
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) throwcpp_id(ERR_WRONGINDEX);
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);
T Autoarr2<T>::get(uint32 index) {
return *getptr(index);
}
template<typename T>
void Autoarr2<T>::Set(uint32 index, T value) {
*GetPtr(index)=value;
void Autoarr2<T>::set(uint32 index, T value) {
*getptr(index)=value;
}
template<typename T>
void Autoarr2<T>::Add(T value) {
void Autoarr2<T>::add(T value) {
if(!values){
values=malloc(sizeof(T*));
//values=(T**)malloc(sizeof(T*));
values=new[sizeof(T*)];
goto create_block;
}
else if(block_length==max_block_length){
block_length=0;
create_block:
values=realloc(values,(blocks_count+1)*sizeof(T*));
values[blocks_count]=malloc(max_block_length*sizeof(T));
values=(T**)realloc(values,(blocks_count+1)*sizeof(T*));
values[blocks_count]=new[](max_block_length*sizeof(T));
blocks_count++;
}
values[blocks_count-1][block_length]=value;
block_length++;
Length++;
length++;
}
template<typename T>

View File

@@ -1,9 +1,5 @@
#include "Hashtable2.hpp"
//
//
//
template<typename TKey, typename TValue>
Hashtable2<TKey, TValue>::Hashtable2() {

View File

@@ -1,3 +1,7 @@
//
//
//
#pragma once
#include "hash.h"

View File

@@ -9,10 +9,6 @@ extern "C" {
#include "errors.h"
#include "cptr.h"
#if __cplusplus
#include "errors.hpp"
#endif
// executes codeblock and prints execution time
#ifdef CLOCK_REALTIME // non-standard high-precision clock
#define optime(opname,repeats,codeblock) ({\

View File

@@ -1,9 +0,0 @@
#include "errors.hpp"
void throwcpp_id(ErrorId eid){
throwcpp_msg(errname(eid));
}
void throwcpp_msg(char* emsg){
__EXIT(emsg);
}

View File

@@ -24,7 +24,7 @@ typedef struct Maybe{
// return it if func doesn't return anything
// .value .errmsg
static const Maybe MaybeNull={UniNull, NULL};
#define MaybeNull (Maybe){UniNull, NULL}
void Maybe_free(Maybe e);
void printMaybe(Maybe e);
@@ -46,6 +46,10 @@ char* __unknownErr( );
default: __unknownErr\
)(E)
#if __cplusplus
#define throw_id(E) __EXIT(((char*)__genErrMsg(errname(E), __FILE__,__LINE__,__func__)))
#define throw_msg(E) __EXIT(((char*)__genErrMsg(E, __FILE__,__LINE__,__func__)))
#endif
#define throw(E) __EXIT(((char*)__genErrMsg((__stringify_err(E)), __FILE__,__LINE__,__func__)))
#define safethrow(E, FREEMEM) { FREEMEM; __RETURN_EXCEPTION(((char*)__genErrMsg((__stringify_err(E)), __FILE__,__LINE__,__func__))); }

View File

@@ -1,8 +0,0 @@
#pragma once
#ifdef __cplusplus
#include "errors.h"
void throwcpp_id(ErrorId eid);
void throwcpp_msg(char* emsg);
#endif