GENERIC: at* ( key assoc -- value/f ? )
GENERIC: set-at ( value key assoc -- )
GENERIC: new-assoc ( size exemplar -- newassoc )
G: assoc-find ( assoc quot -- key value ? )
1 standard-combination ; inline ! quot: key value -- ?
GENERIC: delete-at ( key assoc -- )
GENERIC: clear-assoc ( assoc -- )
GENERIC: assoc-size ( assoc -- n )
GENERIC: assoc-like ( assoc exemplar -- newassoc )
! Additionally, clone should be implemented properly
The major changes from the protocol of a few days ago are the addition of
assoc-like
(which will increase efficiency in some cases) and the removal of key?
(which can easily be, and is, implemented as at* nip
). Additionally, I did some renaming: assoc*
=> at*
, set-assoc
=> set-at
and remove-assoc
=> delete-at
.It was a bit annoying to deal with the Factor internals, but 90% of the problems ended up being my fault anyway. I changed all the code in the Factor distribution (except for Ed's, becuase I heard he would want to do it himself. But if you're reading this, Ed, I'd be fine with changing it if you want me to) and all the unit tests passed--except the ones that failed to begin with. But Factor programmers probably want to know what these changes mean, too. So the rest of this post will be a summary of those changes.
The first thing to know is vocabularies. I moved everything that didn't specifically have to do with hashtables into the
assocs
vocab. All of the remaining words have hash
in the name except for associate
(which makes a new hashtable) and ?set-hash
(which might make a new hashtable). Except for ?set-at
everything in that vocabulary is keeping the same name. Any conforming implementation of the assocs protocol can expect to have all of the other words in the assocs
vocab work properly. And most of them correspond to old, pre-existing hashtable words; they just work on more datatypes now. Some names weren't changed at all, like cache
, which is suitably generic already.In the taxonomy of renaming, there are three groups: dropped prefixes, hash=>assoc changes, and hash=>at changes. These, together with an oddball change, are described below.
Old word | New word(s) |
hash-update | update |
hash-intersect | intersect |
hash-union | union |
hash-keys | keys |
hash-values | values |
hash | at |
hash* | at* |
?hash | ?at |
?hash* | ?at* |
set-hash | set-at |
change-hash | change-at |
hash+ | at+ |
remove-hash | delete-at |
?remove-hash | ?delete-at |
hash-all-with? | assoc-all-with? |
hash-each | assoc-each |
hash-map | assoc-map |
hash-each-with | assoc-each-with |
hash-all? | assoc-all? |
hash-all-with? | assoc-all-with? |
hash-subset | assoc-subset |
hash-subset-with | assoc-subset-with |
hash-empty? | assoc-empty? |
hash-stack | assoc-stack |
clear-hash | clear-assoc |
hashtable= | assoc= |
subhash? | subassoc? |
map>hash | H{ } map>assoc |
make-hash | H{ } make-assoc |
hash-member? | key? |
hash>alist | >alist |
alist>hash | >hashtable |
Of course, there's a difference: every single one of these words is more general and will work on all assocs, not just hashtables. If you have any questions or problems about this change, feel free to ask.
No comments:
Post a Comment