This commit is contained in:
Koichi Nakamura 2021-12-03 21:30:56 +09:00
parent 4bb6829378
commit fc6e1c8ad2
2 changed files with 16 additions and 10 deletions

View file

@ -16,7 +16,7 @@ defined? array-alloc-strategy [unless]
[then]
struct
ptr% field array>buf
cell% field array>buf
int% field array>size
int% field array>capa
end-struct array%

View file

@ -15,22 +15,22 @@ create prime_numbers
0 , 0 , 0 ,
struct
ptr% field table>bucket
ptr% field table>hash ( hash function )
ptr% field table>equal ( equal function for keys )
ptr% field table>entries ( list of entries )
cell% field table>bucket
cell% field table>hash ( hash function )
cell% field table>equal ( equal function for keys )
cell% field table>entries ( list of entries )
int% field table>size ( number of entries )
end-struct table%
struct
ptr% field entry>key
ptr% field entry>value
ptr% field entry>sibling ( pointer to the next entry in bucket )
ptr% field entry>next ( pointer to the next entry in entries )
cell% field entry>key
cell% field entry>value
cell% field entry>sibling ( pointer to the next entry in bucket )
cell% field entry>next ( pointer to the next entry in entries )
int% field entry>hash ( the hash value )
end-struct entry%
: make-table-with-size ( hash equal n -- tbl )
: make-table-with-hint ( hash equal n -- tbl )
bitscan-reverse cells prime_numbers + @ ( n to bucket size )
make-array ( allocate bucket )
@ -43,4 +43,10 @@ end-struct entry%
0 over table>size !
; export
10 constant DEFAULT_TABLE_SIZE_HINT
: make-table ( hash equal -- tbl )
DEFAULT_TABLE_SIZE_HINT make-table-with-hint
; export
}private