general/misc/
csvector.pro
Function: csvector Purpose: This procedure implements the create,add, and read methods for a traditional computer science data structure: the vector.The vector list of elements of any type and of any length. Advantages over array: 1. store heterogenous elements of any type in a list. 2. Lists can grow as large as memory and you don't need to know how big it will be in advance 3. You don't need to worry about how the data is stored Disadvantages over array: 1. You can't directly apply operations to the data structure 2. You are forced to use abstraction Inputs: arg1:the meaning of the argument varies with syntax arg2:the meaning of the argument varies with syntax Keywords: read(optional): set this if you want to read an element length(optional): set this if you want to read the length free(optional): set this if you want to free the vector's memory without creating a leak, it will return the number of elements free'd Outputs: a vector, the internal representation is abstracted, use the methods to access this data structure Syntax(each method is followed by examples): create: v = csvector(some_element) v = csvector(1) v = csvector([1,2]) v = csvector({a:1,b:2}) add: vector = csvector(some_element,vector) v = csvector(1,v) v = csvector('a',v) v = csvector([1,2],v) read: element = csvector(element_index,vector,/read) e = csvector(0,v,/read) ;first element e = csvector(csvector(v,/L)-1,v,/r) ;last element length: length = csvector(vector,/length) l = csvector(v,/l) l = csvector(v,/length) free: num = csvector(vector,/free) temp = csvector(v,/free) NOTES: in the event of overflow during add the vector.a component will double in size Add/Create stores a copy of the element not the element itself If you want to do manual lengths and reads you can look at the code, but I would recommend against cause you are violating abstraction which means the internal representation could change and invalidate your code. This might be worth writing in O.O. idl as well To get type flexibility it uses a pointer for every object Thus if you aren't careful this function will eat your system memory for breakfast. Use heap_gc to clean up if you are running out of memory.
Routines
File attributes
Modification date: | Thu Feb 13 16:43:46 2014 |
Lines: | 48 |