Add string-table

This commit is contained in:
Koichi Nakamura 2021-12-04 20:26:36 +09:00
parent c8bf67c279
commit bfd136f0ed

View file

@ -171,12 +171,23 @@ end-struct entry%
: hash-int ( n -- n )
0 hash-next
; export
;
: make-int-table ( -- tbl )
['] hash-int ['] = make-table
; export
: hash-string ( s -- n )
0 begin over c@ dup while
hash-next
swap 1+ swap
repeat drop nip
;
: make-string-table ( -- tbl )
['] hash-string ['] streq make-table
; export
}private
T{ make-int-table constant A -> }T
@ -207,3 +218,10 @@ T{ A table-values car -> 1 }T
T{ A table-values cdr car -> 2 }T
T{ A table-values cdr cdr car -> 3 }T
T{ A release-table -> }T
T{ make-string-table constant A -> }T
T{ 0 s" zero" A table! -> }T
T{ 1 s" one" A table! -> }T
T{ s" zero" A table@ -> 0 }T
T{ s" one" A table@ -> 1 }T
T{ A release-table -> }T