@@ -154,7 +154,7 @@ typedef HASHBUCKET *HASHSEGMENT;
154
154
typedef struct
155
155
{
156
156
slock_t mutex ; /* spinlock for this freelist */
157
- long nentries ; /* number of entries in associated buckets */
157
+ int64 nentries ; /* number of entries in associated buckets */
158
158
HASHELEMENT * freeList ; /* chain of free elements */
159
159
} FreeListData ;
160
160
@@ -182,18 +182,18 @@ struct HASHHDR
182
182
183
183
/* These fields can change, but not in a partitioned table */
184
184
/* Also, dsize can't change in a shared table, even if unpartitioned */
185
- long dsize ; /* directory size */
186
- long nsegs ; /* number of allocated segments (<= dsize) */
185
+ int64 dsize ; /* directory size */
186
+ int64 nsegs ; /* number of allocated segments (<= dsize) */
187
187
uint32 max_bucket ; /* ID of maximum bucket in use */
188
188
uint32 high_mask ; /* mask to modulo into entire table */
189
189
uint32 low_mask ; /* mask to modulo into lower half of table */
190
190
191
191
/* These fields are fixed at hashtable creation */
192
192
Size keysize ; /* hash key length in bytes */
193
193
Size entrysize ; /* total user element size in bytes */
194
- long num_partitions ; /* # partitions (must be power of 2), or 0 */
195
- long max_dsize ; /* 'dsize' limit if directory is fixed size */
196
- long ssize ; /* segment size --- must be power of 2 */
194
+ int64 num_partitions ; /* # partitions (must be power of 2), or 0 */
195
+ int64 max_dsize ; /* 'dsize' limit if directory is fixed size */
196
+ int64 ssize ; /* segment size --- must be power of 2 */
197
197
int sshift ; /* segment shift = log2(ssize) */
198
198
int nelem_alloc ; /* number of entries to allocate at once */
199
199
bool isfixed ; /* if true, don't enlarge */
@@ -236,7 +236,7 @@ struct HTAB
236
236
237
237
/* We keep local copies of these fixed values to reduce contention */
238
238
Size keysize ; /* hash key length in bytes */
239
- long ssize ; /* segment size --- must be power of 2 */
239
+ int64 ssize ; /* segment size --- must be power of 2 */
240
240
int sshift ; /* segment shift = log2(ssize) */
241
241
242
242
/*
@@ -277,12 +277,12 @@ static bool expand_table(HTAB *hashp);
277
277
static HASHBUCKET get_hash_entry (HTAB * hashp , int freelist_idx );
278
278
static void hdefault (HTAB * hashp );
279
279
static int choose_nelem_alloc (Size entrysize );
280
- static bool init_htab (HTAB * hashp , long nelem );
280
+ static bool init_htab (HTAB * hashp , int64 nelem );
281
281
pg_noreturn static void hash_corrupted (HTAB * hashp );
282
282
static uint32 hash_initial_lookup (HTAB * hashp , uint32 hashvalue ,
283
283
HASHBUCKET * * bucketptr );
284
- static long next_pow2_long ( long num );
285
- static int next_pow2_int (long num );
284
+ static int64 next_pow2_int64 ( int64 num );
285
+ static int next_pow2_int (int64 num );
286
286
static void register_seq_scan (HTAB * hashp );
287
287
static void deregister_seq_scan (HTAB * hashp );
288
288
static bool has_seq_scans (HTAB * hashp );
@@ -355,7 +355,7 @@ string_compare(const char *key1, const char *key2, Size keysize)
355
355
* large nelem will penalize hash_seq_search speed without buying much.
356
356
*/
357
357
HTAB *
358
- hash_create (const char * tabname , long nelem , const HASHCTL * info , int flags )
358
+ hash_create (const char * tabname , int64 nelem , const HASHCTL * info , int flags )
359
359
{
360
360
HTAB * hashp ;
361
361
HASHHDR * hctl ;
@@ -697,7 +697,7 @@ choose_nelem_alloc(Size entrysize)
697
697
* arrays
698
698
*/
699
699
static bool
700
- init_htab (HTAB * hashp , long nelem )
700
+ init_htab (HTAB * hashp , int64 nelem )
701
701
{
702
702
HASHHDR * hctl = hashp -> hctl ;
703
703
HASHSEGMENT * segp ;
@@ -780,20 +780,20 @@ init_htab(HTAB *hashp, long nelem)
780
780
* NB: assumes that all hash structure parameters have default values!
781
781
*/
782
782
Size
783
- hash_estimate_size (long num_entries , Size entrysize )
783
+ hash_estimate_size (int64 num_entries , Size entrysize )
784
784
{
785
785
Size size ;
786
- long nBuckets ,
786
+ int64 nBuckets ,
787
787
nSegments ,
788
788
nDirEntries ,
789
789
nElementAllocs ,
790
790
elementSize ,
791
791
elementAllocCnt ;
792
792
793
793
/* estimate number of buckets wanted */
794
- nBuckets = next_pow2_long (num_entries );
794
+ nBuckets = next_pow2_int64 (num_entries );
795
795
/* # of segments needed for nBuckets */
796
- nSegments = next_pow2_long ((nBuckets - 1 ) / DEF_SEGSIZE + 1 );
796
+ nSegments = next_pow2_int64 ((nBuckets - 1 ) / DEF_SEGSIZE + 1 );
797
797
/* directory entries */
798
798
nDirEntries = DEF_DIRSIZE ;
799
799
while (nDirEntries < nSegments )
@@ -826,17 +826,17 @@ hash_estimate_size(long num_entries, Size entrysize)
826
826
*
827
827
* XXX this had better agree with the behavior of init_htab()...
828
828
*/
829
- long
830
- hash_select_dirsize (long num_entries )
829
+ int64
830
+ hash_select_dirsize (int64 num_entries )
831
831
{
832
- long nBuckets ,
832
+ int64 nBuckets ,
833
833
nSegments ,
834
834
nDirEntries ;
835
835
836
836
/* estimate number of buckets wanted */
837
- nBuckets = next_pow2_long (num_entries );
837
+ nBuckets = next_pow2_int64 (num_entries );
838
838
/* # of segments needed for nBuckets */
839
- nSegments = next_pow2_long ((nBuckets - 1 ) / DEF_SEGSIZE + 1 );
839
+ nSegments = next_pow2_int64 ((nBuckets - 1 ) / DEF_SEGSIZE + 1 );
840
840
/* directory entries */
841
841
nDirEntries = DEF_DIRSIZE ;
842
842
while (nDirEntries < nSegments )
@@ -887,7 +887,7 @@ hash_stats(const char *caller, HTAB *hashp)
887
887
HASHHDR * hctl = hashp -> hctl ;
888
888
889
889
elog (DEBUG4 ,
890
- "hash_stats: Caller: %s Table Name: \"%s\" Accesses: " UINT64_FORMAT " Collisions: " UINT64_FORMAT " Expansions: " UINT64_FORMAT " Entries: %ld Key Size: %zu Max Bucket: %u Segment Count: %ld" ,
890
+ "hash_stats: Caller: %s Table Name: \"%s\" Accesses: " UINT64_FORMAT " Collisions: " UINT64_FORMAT " Expansions: " UINT64_FORMAT " Entries: " INT64_FORMAT " Key Size: %zu Max Bucket: %u Segment Count: " INT64_FORMAT ,
891
891
caller != NULL ? caller : "(unknown)" , hashp -> tabname , hctl -> accesses ,
892
892
hctl -> collisions , hctl -> expansions , hash_get_num_entries (hashp ),
893
893
hctl -> keysize , hctl -> max_bucket , hctl -> nsegs );
@@ -993,7 +993,7 @@ hash_search_with_hash_value(HTAB *hashp,
993
993
* Can't split if running in partitioned mode, nor if frozen, nor if
994
994
* table is the subject of any active hash_seq_search scans.
995
995
*/
996
- if (hctl -> freeList [0 ].nentries > (long ) hctl -> max_bucket &&
996
+ if (hctl -> freeList [0 ].nentries > (int64 ) hctl -> max_bucket &&
997
997
!IS_PARTITIONED (hctl ) && !hashp -> frozen &&
998
998
!has_seq_scans (hashp ))
999
999
(void ) expand_table (hashp );
@@ -1332,11 +1332,11 @@ get_hash_entry(HTAB *hashp, int freelist_idx)
1332
1332
/*
1333
1333
* hash_get_num_entries -- get the number of entries in a hashtable
1334
1334
*/
1335
- long
1335
+ int64
1336
1336
hash_get_num_entries (HTAB * hashp )
1337
1337
{
1338
1338
int i ;
1339
- long sum = hashp -> hctl -> freeList [0 ].nentries ;
1339
+ int64 sum = hashp -> hctl -> freeList [0 ].nentries ;
1340
1340
1341
1341
/*
1342
1342
* We currently don't bother with acquiring the mutexes; it's only
@@ -1417,9 +1417,9 @@ hash_seq_search(HASH_SEQ_STATUS *status)
1417
1417
HTAB * hashp ;
1418
1418
HASHHDR * hctl ;
1419
1419
uint32 max_bucket ;
1420
- long ssize ;
1421
- long segment_num ;
1422
- long segment_ndx ;
1420
+ int64 ssize ;
1421
+ int64 segment_num ;
1422
+ int64 segment_ndx ;
1423
1423
HASHSEGMENT segp ;
1424
1424
uint32 curBucket ;
1425
1425
HASHELEMENT * curElem ;
@@ -1548,11 +1548,11 @@ expand_table(HTAB *hashp)
1548
1548
HASHHDR * hctl = hashp -> hctl ;
1549
1549
HASHSEGMENT old_seg ,
1550
1550
new_seg ;
1551
- long old_bucket ,
1551
+ int64 old_bucket ,
1552
1552
new_bucket ;
1553
- long new_segnum ,
1553
+ int64 new_segnum ,
1554
1554
new_segndx ;
1555
- long old_segnum ,
1555
+ int64 old_segnum ,
1556
1556
old_segndx ;
1557
1557
HASHBUCKET * oldlink ,
1558
1558
* newlink ;
@@ -1620,7 +1620,7 @@ expand_table(HTAB *hashp)
1620
1620
currElement = nextElement )
1621
1621
{
1622
1622
nextElement = currElement -> link ;
1623
- if ((long ) calc_bucket (hctl , currElement -> hashvalue ) == old_bucket )
1623
+ if ((int64 ) calc_bucket (hctl , currElement -> hashvalue ) == old_bucket )
1624
1624
{
1625
1625
* oldlink = currElement ;
1626
1626
oldlink = & currElement -> link ;
@@ -1644,9 +1644,9 @@ dir_realloc(HTAB *hashp)
1644
1644
{
1645
1645
HASHSEGMENT * p ;
1646
1646
HASHSEGMENT * old_p ;
1647
- long new_dsize ;
1648
- long old_dirsize ;
1649
- long new_dirsize ;
1647
+ int64 new_dsize ;
1648
+ int64 old_dirsize ;
1649
+ int64 new_dirsize ;
1650
1650
1651
1651
if (hashp -> hctl -> max_dsize != NO_MAX_DSIZE )
1652
1652
return false;
@@ -1780,8 +1780,8 @@ hash_initial_lookup(HTAB *hashp, uint32 hashvalue, HASHBUCKET **bucketptr)
1780
1780
{
1781
1781
HASHHDR * hctl = hashp -> hctl ;
1782
1782
HASHSEGMENT segp ;
1783
- long segment_num ;
1784
- long segment_ndx ;
1783
+ int64 segment_num ;
1784
+ int64 segment_ndx ;
1785
1785
uint32 bucket ;
1786
1786
1787
1787
bucket = calc_bucket (hctl , hashvalue );
@@ -1814,33 +1814,29 @@ hash_corrupted(HTAB *hashp)
1814
1814
1815
1815
/* calculate ceil(log base 2) of num */
1816
1816
int
1817
- my_log2 (long num )
1817
+ my_log2 (int64 num )
1818
1818
{
1819
1819
/*
1820
1820
* guard against too-large input, which would be invalid for
1821
1821
* pg_ceil_log2_*()
1822
1822
*/
1823
- if (num > LONG_MAX / 2 )
1824
- num = LONG_MAX / 2 ;
1823
+ if (num > PG_INT64_MAX / 2 )
1824
+ num = PG_INT64_MAX / 2 ;
1825
1825
1826
- #if SIZEOF_LONG < 8
1827
- return pg_ceil_log2_32 (num );
1828
- #else
1829
1826
return pg_ceil_log2_64 (num );
1830
- #endif
1831
1827
}
1832
1828
1833
- /* calculate first power of 2 >= num, bounded to what will fit in a long */
1834
- static long
1835
- next_pow2_long ( long num )
1829
+ /* calculate first power of 2 >= num, bounded to what will fit in a int64 */
1830
+ static int64
1831
+ next_pow2_int64 ( int64 num )
1836
1832
{
1837
1833
/* my_log2's internal range check is sufficient */
1838
1834
return 1L << my_log2 (num );
1839
1835
}
1840
1836
1841
1837
/* calculate first power of 2 >= num, bounded to what will fit in an int */
1842
1838
static int
1843
- next_pow2_int (long num )
1839
+ next_pow2_int (int64 num )
1844
1840
{
1845
1841
if (num > INT_MAX / 2 )
1846
1842
num = INT_MAX / 2 ;
0 commit comments