List and Map iterators

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

List and Map iterators

Post by Demivec »

PureBasic currently has a limitation of only being able to have one current element for each List or Map.

I propose the possibility of creating a separate iterator type that can be used with lists or maps.

Similar solutions were made in the past when v4.00 of PureBasic was created. Remember the UseImage(), UseFile(), etc. that were removed in v4.00. Those changes made to v4.00 made it possible to access more than one object in those respective libraries at the same time. Something similar is needed for the LinkedList and Map librairies.

An iterator solution could take this form:

Code: Select all

NewList a.i()
AddElement(a()): a() = 1
AddElement(a()): a() = 5
AddElement(a()): a() = 3

;create an iterator which creates a pointer to a header for a list or map of a given type, but with its own current element
NewListIterator x.i() ;or NewMapIterator

;initialize the iterator to point to a specific list or map, this allows it to service more than one list or map of the same type
SetListIterator(x(), a()) ;or SetMapIterator

ResetList(x()) ;this would reset the current element in x(), not a()
While NextListElement(x())
  Debug a() + x() ;would display results for 3 + 1, 3 + 5, 3 + 3
Wend

;another example
ForEach x()
  ForEach a()
    If a() = x()
      Debug a() ;should display 1, 5, 3
    EndIf 
  Next
Next
Commands such as AddElement() or DeleteElement() would affect the original list or map header which the inerator is set to point to, but would affect only the current element stored in the iterator.

@Edit: corrected spelling of iterator. :P
Last edited by Demivec on Tue Aug 03, 2010 8:59 am, edited 1 time in total.
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Re: List and Map itinerators

Post by akj »

@Demivec:

Presumably you mean iterator, not itinerator
Anthony Jordan
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: List and Map iterators

Post by Demivec »

akj wrote:@Demivec:

Presumably you mean iterator, not itinerator
I do, I tried to spell it about 15 different ways and had settled on the one I thought was the least incorrect. :D Thanks for the correction, I've updated the first posting and topic title.
Post Reply