[antlr-interest] C Runtime - list container suggestions

Gavin Lambert antlr at mirality.co.nz
Thu Aug 16 01:49:49 PDT 2007


At 06:56 16/08/2007, Cameron Esfahani wrote:
>Then what would the difference between a list and a vector be?

"List" is a more general term and is frequently used to describe 
any sort of collection, although it is more commonly used to 
describe an ordered collection rather than a hashed one (those 
tend to be called "hashtables", "maps", or "dictionaries").

Or if you prefer, "list" is an abstract base class, of which one 
implementation is "vector" and another is "linked list".  (This is 
not really accurate, it's just using the terms in evil ways to try 
to present a point.)

>The reason I thought that list would supported persistent IDs is 
>that the list routines are built on top of Jim's hash table 
>routines.

I wasn't really referring to any of the current implementation -- 
I was just saying what those particular terms mean to me, and how 
I've commonly heard them used in the wider world -- and so 
consequently what sort of behaviour people would tend to expect 
when presented with a class-like structure that called itself a 
"list".

>If that's the case, then one way to fix list to handle persistent 
>IDs would be to use an increasing integer value as the key, 
>supplied by list add(), to the hash routine.  Right now, it uses 
>the size of the hash, which means it can decrease when items are 
>deleted, causing keys to collide.

That solves the collision problem but doesn't solve the indexing 
problem (where if the first element is "list[0]" and then you 
delete it, you expect to see the former second element become 
"list[0]").

I just don't think that something that calls itself a list should 
exhibit dictionary-like behaviour.  And I don't think 
dictionary-like behaviour is necessary in something like a list or 
tree of tokens.

As always, though, this is just my opinion :)  Offer void where 
prohibited. 



More information about the antlr-interest mailing list