[Implemented] Native ability to concatenate and split lists.

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

[Implemented] Native ability to concatenate and split lists.

Post by Demivec »

For reference see this thread topic.

The concatenation of 2 lists should ideally only involve changing 2 sets of pointers and the lists respective header data (i.e. size, and first/last element ptrs).

Without a native implementation it is necessary to loop through each list element and make a copy of it (via assignment) and then removing the original elements (via delete or ClearList()). The more in a list the longer the process. One of linked-list's advantages is that it allows the links to be modified easily. It would be useful to allow this kind of rearranging of elements between linked-lists.


Suggested command formats:

ConcatenateList(sourceList(), destList()) ;move elements from current element in sourceList() to destList() starting after current element
MoveListElements(sourceList(), destList(), numElements) ;move upto numElements from current element in sourceList to destList starting after current element.


@Edit: see KJ67 suggestions below for splitting lists.
Last edited by Demivec on Sat Aug 14, 2010 1:45 pm, edited 3 times in total.
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Native ability to concatenate lists.

Post by Little John »

Demivec,

thank you for writing this feature request. I probably wouldn't have been able to express the situation that clearly in English.

Regards, Little John
User avatar
KJ67
Enthusiast
Enthusiast
Posts: 218
Joined: Fri Jun 26, 2009 3:51 pm
Location: Westernmost tip of Norway

Re: Native ability to concatenate lists.

Post by KJ67 »

The ability to cut, divide and maybe also copy a part of a linked list would be much faster using looping copy/delete.

Code: Select all

; Pseudo code...
NewList A()=[0,1,2,3,4,5,6,7,8,9,10]
NewList B()=CutList( A(), 4)
Would give;
A()=[0,1,2,3]
B()=[4,5,6,7,8,9,10]

; ___________________________________________
; This would allow code as
SortContactListbyMaleFemale(MyList())
NewList Females()=CutList(MyList(), indexoffirstgirl)
; MyList() would now be ‘Male()’ part
ForEach MyList()
  ForEach Female()
    Check_if_dating(MyList(), Female())
  Next
Next
The best preparation for tomorrow is doing your best today.
Post Reply