Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
cursor/stream/c++ iterator class?
Eric Mahurin
4/27/2005 10:43:00 PM
I've read a few discussions/comparisons between enumerators
(internal iterators) vs. cursors (external iterators). From
what I gather those discussions in favor of enumerators assume
the application is a simple single pass read-only processing of
all/some of the elements in a collection. You do this a lot
with a collection and I like enumerators best for doing it.
But when you are doing something more complex, enumerators
don't cut it.
I'm still working on some general parser classes (and a lexer
is one of these parsers) where the collection is a sequence of
characters (lexer/parser) or a sequence of tokens (parser). I
started making my own API for accessing these, but now I'm just
going ahead and making a general cursor API. Am I duplicating
anything else? Here are the kinds of things you'll be able to
do with this cursor interface:
get Next/Prev/After/Before
move Next/Prev
replace Next/Prev/After/Before (optionally get what is
replaced)
delete After/Before (optionally retrieve what's deleted)
insert After/Before
get position (position could be any type of object)
set position
release position (release buffering needed for unidirection
cursor - i.e IO pipe)
buffered? - query whether there are any non-released positions
The methods above that read/write at the cursor will work on
one element at a time or a string/array/N of them.
get/move/delete will even be able to get so many elements up to
a certain string /array of them - like gets("\n"). I'm trying
to make this have a superset of the functions in IO in addition
to handling sequences of anything.
I would hope this API could be used to access and modify a wide
variety of ordered collections - strings, arrays, files/IO,
single/double linked lists, circular buffers, text editor
buffers, etc. It could possibly be used for unordered
collections (i.e. hashes) in a read-only manner but I see no
advantage over an enumerator in that case.
Eric
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail...
1 Answer
Simon Strandgaard
4/28/2005 6:11:00 AM
0
On 4/28/05, Eric Mahurin <eric_mahurin@yahoo.com> wrote:
> I've read a few discussions/comparisons between enumerators
> (internal iterators) vs. cursors (external iterators). From
> what I gather those discussions in favor of enumerators assume
> the application is a simple single pass read-only processing of
> all/some of the elements in a collection. You do this a lot
> with a collection and I like enumerators best for doing it.
> But when you are doing something more complex, enumerators
> don't cut it.
[snip]
I have made a lib containing some external iterators, see:
http://aeditor.rubyforge.org...
download it here:
http://rubyforge.org/frs/download.php/704/iterat...
--
Simon Strandgaard
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
cursor/stream/c++ iterator class?
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password