Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pssrecom committed Jan 12, 2020
1 parent f51ea2c commit b9b8947
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 48 deletions.
22 changes: 17 additions & 5 deletions Project/FastDict.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,15 @@ class FastDict
{
if (m_count > 0)
{
int32_t i = 0;

//重置所有储槽
for (int32_t i = 0; i < m_capacity; i++)
for (i = 0; i < m_capacity; i++)
{
m_buckets[i] = -1;
}
//清除项目数据
for (int32_t i = 0; i < m_count; i++)
for (i = 0; i < m_count; i++)
{
VariantClear(&m_items[i].key);
VariantClear(&m_items[i].value);
Expand Down Expand Up @@ -848,14 +850,24 @@ class FastDict
//取得新扩字节数
int32_t newCapacity = HashHelpers::ExpandPrime(m_capacity);//新扩容量
int32_t blocks = sizeof(int32_t) + sizeof(dicitem); //每个储槽和项目占用的字节数
DWORDLONG newSize = blocks * (DWORDLONG)newCapacity;//字节数
#if (_MSC_VER <= 1200) //VC++ 6.0
int64_t newSize = blocks * (int64_t)newCapacity;//字节数
#else
uint64_t newSize = blocks * (uint64_t)newCapacity;//字节数
#endif

//取得内存可用空间
MEMORYSTATUSEX ms;
ms.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&ms);
DWORDLONG ullAvailPhys = ms.ullAvailPhys; //字节数
DWORDLONG ullAvailVirtual = ms.ullAvailVirtual; //字节数

#if (_MSC_VER <= 1200) //VC++ 6.0
int64_t ullAvailPhys = (int64_t)ms.ullAvailPhys; //字节数
int64_t ullAvailVirtual = (int64_t)ms.ullAvailVirtual; //字节数
#else
uint64_t ullAvailPhys = (uint64_t)ms.ullAvailPhys; //字节数
uint64_t ullAvailVirtual = (uint64_t)ms.ullAvailVirtual; //字节数
#endif

//已经超出了可用的虚拟内存,但还没有超过可用的物理内存,按可用虚拟内存的50%申请内存
if (newSize >= ullAvailVirtual && newSize < ullAvailPhys)
Expand Down
33 changes: 21 additions & 12 deletions Project/HashHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,22 @@

//类型定义
#if defined(_MSC_VER) && (_MSC_VER < 1600)
typedef signed char int8_t;
typedef short int16_t;
typedef int int32_t;
typedef long long int64_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
typedef unsigned __int64 uint64_t;
typedef signed char int8_t;
typedef short int16_t;
typedef int int32_t;
#if (_MSC_VER <= 1200) //VC++ 6.0
typedef __int64 int64_t;
#else
typedef long long int64_t;
#endif
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
#if (_MSC_VER <= 1200) //VC++ 6.0
typedef unsigned __int64 uint64_t;
#else
typedef unsigned long long uint64_t;
#endif
#else
#include <stdint.h>
#endif
Expand Down Expand Up @@ -121,19 +128,21 @@ class HashHelpers
//获得素数
static __forceinline int GetPrime(int min)
{
int32_t i = 0;

//获得数组元素的数量
int32_t count = (sizeof(primes) / sizeof(primes[0]));

//未设置(0),则从primes表中取出一个 >= min的最小素数
for (int32_t i = 0; i < count; i++)
for (i = 0; i < count; i++)
{
int prime = primes[i];
if (prime >= min) return prime;
}

//超出primes的最大值,则运算一个
//outside of our predefined table. compute the hard way.
for (int32_t i = (min | 1); i < MaxHashTable; i += 2)
for (i = (min | 1); i < MaxHashTable; i += 2)
{
if (IsPrime(i) && ((i - 1) % DefaultHashPrime != 0))
return i;
Expand Down
Binary file added Project/ReleaseMinDependency/TFastDict-xp.dll
Binary file not shown.
36 changes: 10 additions & 26 deletions Project/TFastDict.dsp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions Project/TFastDict2005.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -862,10 +862,6 @@
Name="Header Files"
Filter="h;hpp;hxx;hm;inl"
>
<File
RelativePath=".\FastDataDict.h"
>
</File>
<File
RelativePath=".\FastDict.h"
>
Expand Down
2 changes: 1 addition & 1 deletion Test/vbpTest.vbw
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
frmMain = 155, 155, 838, 529, Z, 132, 132, 817, 501, C
frmMain = 155, 155, 838, 529, , 132, 132, 817, 501, C
cTiming = 78, 78, 842, 517,
modMain = 0, 0, 0, 0, C

0 comments on commit b9b8947

Please sign in to comment.