Friday, March 16, 2007

VList in Java

Two days ago I was reading this article about LISP like lists implemented in Java,
which reminded me I had written an implementation of a VList in Java. It can be found
here, along with a unit test.I make no garantee this is the best or fastest implementation possible!

It implements: get(n), first (head in Haskell), rest() (tail in Haskell), size(), iterator() and map(Mapper), where Mapper is the mapping interface I mentioned earlier.

It's using Java Generics of course. Am I right in thinking there is no way with Java generics to get rid of the compilation warnings and of the necessity of passing the Class object in the code that creates a new array of the generic type?

10 comments:

Tembrel said...

You can get rid of the Class argument to the VList constructor only by using Object[] internally, which would involve lots of casts.

The way you are doing it is better, though.

Anonymous said...

Did you see any good and deep article about VList? daVinci@mail.ru

JP Moresmau said...

http://en.wikipedia.org/wiki/VList is the first place I can think of...

Anonymous said...

What about Remove(i) or Insert(i) opertions? Is there any info about it?

JP Moresmau said...

Mmmhh, I don't think a VList would be the best for these operations. I know there's some more exotic varieties of linked list that can maybe give you good performance for these operations. Funnily, I don't really use these operations a lot. Strive to have algorithms that insert and remove at one extremity of a list...

Anonymous said...

Does anyone know of a working link for the code mentioned in this article?

JP Moresmau said...

Sorry, all the links are dead as I didn't renew my account with the hosting provider where the code was. I'll find another place to put it.

JP Moresmau said...

OK, links are fixed, I moved the code to a little Google AppEngine application I made

Anonymous said...
This comment has been removed by a blog administrator.
艾力绅 said...

The links of code mentioned in this article doesn't work. could you put the code into github.com?