/
wrapped-docs.factor
38 lines (33 loc) · 1.39 KB
/
wrapped-docs.factor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
! Copyright (C)2023 Raghu Ranganathan.
! See https://factorcode.org/license.txt for BSD license.
USING: assocs help.markup help.syntax kernel ;
IN: hashtables.wrapped
HELP: wrap-key
{ $values
{ "key" object } { "wrapped-hash" object }
{ "wrapped-key" object }
}
{ $description "An object that wraps a key and provides a different hashcode implementation." } ;
HELP: wrapped-hashtable
{ $class-description "A hashtable that uses wrapped keys to provide a different hashcode implementation." } ;
ARTICLE: "hashtables.wrapped" "Wrapped Hashtable protocol"
"The " { $vocab-link "hashtables.wrapped" } " describes a protocol for defining hashtables that "
"use custom hashing algorithms."
$nl
"To create a custom wrapped hashtable, you must define a wrapper for your keys (usually a tuple class)."
" For this wrapper, you have to define the following generics:"
{ $list
{ { $link hashcode* } " for your wrapper, which will contain the hashing algorithm you want to use. " }
{ { $link wrap-key } " which is effectively a constructor for wrapping keys." }
{ { $link equal? } " to check for equality of keys." }
}
"Other relevant generics are " { $link clone } " and " { $link new-assoc } "."
$nl
"Examples of wrapped hastable objects can be seen in:"
{ $list
{ $vocab-link "hashtables.identity" }
{ $vocab-link "hashtables.sequences" }
{ $vocab-link "hashtables.numbers" }
}
;
ABOUT: "hashtables.wrapped"