some small changes

This commit is contained in:
Timerix22 2022-07-17 16:56:49 +03:00
parent bee08e4754
commit 16957ced1a
4 changed files with 20 additions and 19 deletions

View File

@ -1,5 +1,8 @@
#pragma once #pragma once
#include "../base/base.h"
#define __AUTOARR2_MAX_BLOCK_LENGTH_DEFAULT 64
#define Autoarr2_NO_REZULT (uint32)-1 #define Autoarr2_NO_REZULT (uint32)-1
@ -32,22 +35,17 @@ public:
uint32 search(T& value, cmp_func_lambda cmpf); uint32 search(T& value, cmp_func_lambda cmpf);
}; };
#define __AUTOARR2_MAX_BLOCK_LENGTH_DEFAULT 64
template<typename T> template<typename T>
Autoarr2<T>::Autoarr2() { Autoarr2<T>::Autoarr2(uint16 _max_block_length) {
values = NULL; values = NULL;
block_length = 0; block_length = 0;
blocks_count = 0; blocks_count = 0;
length = 0; length = 0;
max_block_length=__AUTOARR2_MAX_BLOCK_LENGTH_DEFAULT; max_block_length=_max_block_length;
} }
template<typename T> template<typename T>
Autoarr2<T>::Autoarr2(uint16 _max_block_length) : Autoarr2() { Autoarr2<T>::Autoarr2() : Autoarr2(__AUTOARR2_MAX_BLOCK_LENGTH_DEFAULT) {}
max_block_length=_max_block_length;
}
template<typename T> template<typename T>
Autoarr2<T>::~Autoarr2() { Autoarr2<T>::~Autoarr2() {

View File

@ -143,7 +143,8 @@ bool Hashtable2<TKey, TVal>::tryGet(TKey key, TVal* output){
} }
template<typename TKey, typename TVal> template<typename TKey, typename TVal>
void Hashtable2<TKey, TVal>::expand(){ printf("expand\n"); fflush(stdout); void Hashtable2<TKey, TVal>::expand(){
printf("expand\n"); fflush(stdout);
if(hein>=_HT_HEIN_MAX) if(hein>=_HT_HEIN_MAX)
throw_id(ERR_MAXLENGTH); throw_id(ERR_MAXLENGTH);
@ -169,7 +170,8 @@ void Hashtable2<TKey, TVal>::expand(){ printf("expand\n"); fflush(stdout);
} }
template<typename TKey, typename TVal> template<typename TKey, typename TVal>
void Hashtable2<TKey, TVal>::add(TKey& key, TVal& value, HT_HASH_T keyHash, HT_HEIGHT_T rowN){ printf("add\n"); fflush(stdout); void Hashtable2<TKey, TVal>::add(TKey& key, TVal& value, HT_HASH_T keyHash, HT_HEIGHT_T rowN){
printf("add\n"); fflush(stdout);
Autoarr2<KeyValue>* row=rows[rowN]; Autoarr2<KeyValue>* row=rows[rowN];
if(row->length == _HT_ARR_BC*_HT_ARR_BL) if(row->length == _HT_ARR_BC*_HT_ARR_BL)
expand(); expand();

View File

@ -54,7 +54,6 @@ char* __unknownErr( );
#else #else
#define throw(E) __EXIT(((char*)__genErrMsg((__stringify_err(E)), __FILE__,__LINE__,__func__))) #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__))); } #define safethrow(E, FREEMEM) { FREEMEM; __RETURN_EXCEPTION(((char*)__genErrMsg((__stringify_err(E)), __FILE__,__LINE__,__func__))); }
#endif
#define try(_funcCall, _rezult, freeMem) Maybe _rezult=_funcCall; if(_rezult.errmsg){\ #define try(_funcCall, _rezult, freeMem) Maybe _rezult=_funcCall; if(_rezult.errmsg){\
freeMem;\ freeMem;\
@ -67,6 +66,8 @@ char* __unknownErr( );
__EXIT(_rezult.errmsg);\ __EXIT(_rezult.errmsg);\
}else }else
#endif
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@ -26,7 +26,7 @@ std::shared_ptr<char> genkey(uint32 i){
} }
void fill(HT_TYPE* ht){ void fill(HT_TYPE* ht){
for(uint32 i=0;i<251;i++) for(uint32 i=0;i<260;i++)
ht->add(genkey(i), 555666); ht->add(genkey(i), 555666);
print_hashtable(ht); print_hashtable(ht);
} }
@ -49,8 +49,8 @@ void test_hashtable2(){
[](TKey k) { return hashs(hash_sdbm32,k.get()); }); [](TKey k) { return hashs(hash_sdbm32,k.get()); });
#else #else
HT_TYPE* ht=new HT_TYPE( HT_TYPE* ht=new HT_TYPE(
[](TKey k) { return hashs(hash_sdbm32,k.get()); }, [](TKey k) -> HT_HASH_T { return hashs(hash_sdbm32,k.get()); },
[](TKey k0, TKey k1) { return cptr_compare(k0.get(), k1.get()); }); [](TKey k0, TKey k1) -> bool { return cptr_compare(k0.get(), k1.get()); });
#endif #endif
printf("\e[92mhashtable created\n"); printf("\e[92mhashtable created\n");
print_hashtable(ht); print_hashtable(ht);