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:
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
assocsvocab. All of the remaining words have
hashin the name except for
associate(which makes a new hashtable) and
?set-hash(which might make a new hashtable). Except for
?set-ateverything 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
assocsvocab 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)|
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.