From a1fa748e98e37d9bc8bf4840ce36d3b8de6570e9 Mon Sep 17 00:00:00 2001 From: Koichi Nakamura Date: Fri, 3 Dec 2021 22:00:30 +0900 Subject: [PATCH] Add make-int-table --- lib/table.fs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/table.fs b/lib/table.fs index 9539570..0b60155 100644 --- a/lib/table.fs +++ b/lib/table.fs @@ -41,7 +41,7 @@ end-struct entry% tuck table>hash ! 0 over table>entries ! 0 over table>size ! -; export +; 10 constant DEFAULT_TABLE_SIZE_HINT @@ -49,4 +49,32 @@ end-struct entry% DEFAULT_TABLE_SIZE_HINT make-table-with-hint ; export +: release-table ( tbl -- ) + dup table>entries @ + begin ?dup while + dup entry>next @ + swap + free + repeat + dup table>bucket @ release-array + free +; export + +( tables for major builtin types ) +: hash-next ( n1 n2 -- n3 ) + + 6122117 * 1627577 + +; + +: hash-int ( n -- n ) + 0 hash-next +; export + +: make-int-table ( -- tbl ) + ['] hash-int ['] = make-table +; export + +." ===========" cr + }private + +T{ make-int-table release-table -> }T