Solid Fluid System Solutions  
Home Software About Hardware Firmware

Document Icon VConsole (Library)
Document Icon Crypto
Document Icon Archive
Document Icon Container
Document Icon Pipe
Document Icon Compress
Document Icon Math
Document Icon Vector
Document Icon DateTime
Current Document Icon List/Array
Document Icon HashIntegerFloat
Document Icon Database
Document Icon Thread
Document Icon String
Document Icon Machine
Document Icon Regex
Document Icon SGMLParse
Document Icon HTTPHeader
Document Icon Comm
Document Icon Collab
Document Icon HierAgent
Document Icon Resource
Document Icon Colour
Document Icon Image

List/Array

VList and VArray are two implementations of 1 dimensional object storage with, identical interfaces.

Internally list is implemented as a linked list, whilst array is implemented as a scalable array. At the interface, each is compatible with the other.

There are clear benefits and disadvantages to lists and arrays. Lists work quickly with sequential access particularly when many item additions and removals are made in the middle of the list. They do not enjoy sporadic access, by index, in the middle of the list. Arrays work quickly when access is by index, or not sequential, but they do not enjoy items added or removed in the middle of the array. Providing both types with identical interfaces allows a pragmatic choice between the approaches without significant recoding.

Both classes support find and sort. There are two kinds of sort. All three operate on the basis of a _cdecl callback function.

  • The find callback automatically iterates the list/array passing the current object. The user may inspect the object and return a found status.
  • The first sort function is similar in operation but implements a bubble sort. The callback passes two objects in and the function must inspect them and decide if left is greater than right.
  •  The second sort function is a partial sort, or nth element sort. The request takes the index of the sorted list item to find. The callback passes the current object and expects the "value" of that object to be returned. On completion the list is not sorted, but the requested index is located in the list as it would be if the list were sorted. Indexed objects with value less than that of the chosen index are guaranteed to be before, indexes greater are guaranteed to be after.

The nth element algorithm is similar to the quicksort algorithm, which is not provided. nth element is faster because it does less. When a list is very random quicksort appears not to have a significant advantage over bubblesort. If one needs to implement regular sort operations it seems better to use classes from the Hash/Integer/Float group described later which actually store data in a sorted form, and thus never require explicit sorting.

Both list and array provide subclasses implemented using the VGeneric object, to allow lists of integer and double types, in addition to standard VObject pointer type.

Copyright © Solid Fluid 2007-2022
Last modified: SolFlu  Mon, 08 Jun 2009 00:42:19 GMT