@bmcclure: No, you don't come off too strongly, and please don't back down either. My feelings may be hurt, but that shows that I care about this library. Also, I do feed off yals suggestions, and with them, this library can become even better.
@bmcclure: I ran a test of inserting an object into the first position of a Vector 1000 times (which means that the all the objects must be moved down, each time). Also, I didn't set the initial capacity, so it had to reallocate seven times (10 * 2^7 = 1280). The first 10 is the default initial capacity. The default behavior is to double each time.
Here is my test code.
Each takes about 1/2 second, on my computer, at Count = 1000. The results I got suggest that initializing the Vector to the correct size takes longer. Also, Cdll takes even longer than that. This really suprises me - checking to see if it's a design flaw.
Code:
;number of objects to add
Count := 1000
/*
Vector (no initial size set)
*/
;don't set initial size
myVector := Vector_new()
start := A_TickCount
Loop, %Count%
{
;automatically resizes as needed
Vector_add(myVector, 1, String_new(A_Index))
}
;total time
VectorNoInit := A_TickCount - start
;free memory
Vector_destroy(myVector)
/*
Vector (initial size set)
*/
;set initial size
myVector := Vector_new(Count)
start := A_TickCount
Loop, %Count%
{
Vector_add(myVector, 1, String_new(A_Index))
}
VectorInit := A_TickCount - start
;free memory
Vector_destroy(myVector)
/*
Cdll
*/
myCdll := Cdll_new()
start := A_TickCount
Loop, %Count%
{
;add before (last position)
;inserts don't move memory around
Cdll_addBefore(myCdll, String_new(A_Index))
}
CdllTime := A_TickCount - start
MsgBox, % "Vector (no init): " . VectorNoInit
. "`nVector (init): " . VectorInit
. "`nCdll: " . CdllTime
Some planned changes:
I'm going to add "index wrapping" for all functions that use indexes. So, 0 can be used to instead of Vector_size(), -1 for Vector_size() - 1, etc. I'll add the same ability to Array, which uses Array_length() to return the "size".
Also, going to document, if I haven't that Vector_add(VectorObject, object) can be called to add to the end of a Vector.
Seach features:
There's nothing in development for search features, but I think I know how I want to do it, so I'll start. I haven't heard any feedback and so didn't want to add it yet. Now that I heard there is a need, I'll add it how I thought. A identical search functions will be added to each of Array, Cdll, and Vector Classes.
Below are my thoughts, feedback welcome.
Syntax:
Code:
Vector_indexOf(VectorObject, value, index = 1, useFunction = "getValue")
Indexes will "wrap", entering -1 will start at
Vector_size() - 1, -2 will start at
Vector_size() - 2, etc.
The function will search through VectorObject and call the specified function on each object in the Vector (starting at the specified index).
Then, the return of the function will be compared to specified value - the index for the first matching object will be returned.
Note: by using different functions, you can use the same search function to look for different values. Also, the function can be ANY function in the Class. Ex. you could compare Rectangle objects by area (via Rectangle_getArea - function = "getArea"). Likewise, user-added functions, provided they use the standard naming, will be usable as well. Ex. you can search a Rectangle by color (via Rectangle_getColor - function = "getColor").
Should I add a final parameter, <includedClasses> to search only objects of the specified Class? The default value would be "" - meaning all objects will be compared.
Edit:
I forgot to mention that the called function MUST have the following syntax:
Code:
%ClassName%_%useFunction%(ClassObject)
Example:
If you have a Vector of Student objects, you might have a getName function and a getStudentID function.
To search for a student ("animeaime") by name, you would call:
Code:
Vector_indexOf(VectorObject, "animeaime", 1, "getName")
This would, for each object in the Vector, call its getName function.
Ex.
if Vector[1] is a String object, it would call String_getName (which doesn't exist), so it wouldn't be a match and continue. It would then move to Vector[2]. Let's say that is a Student object whose getName function returns "animeaime" (hey, that's me). Then, the return would be 2. If there is no match, zero is returned. Therefore, you can use this as a quasi-boolean to see if the object is in the list.
Code:
if Vector_indexOf(VectorObject, "animeaime", 1, "getName")
{
MsgBox, % "animeaime is in VectorObject."
}
I'll also add the getAddress function to Cdll. For Cdll, since it lacks "indexes", I think it would be best to return the address. Well, actually, it does have indexes, so I could return an index. Also, I'll add a get/set function (that work on index). However, such get/set methods would be O(n) - linear time versus O(1) - constant time (for Array and Vector).
There will also be a findMatch function which mimics indexOf, but returns the address for the matching object (instead of the index) - looking for suggestions for function name.
Also, any other functionality can be added, so keep the ideas coming. I'm going to take a little break from working on my libraries (after I add search). I need to get back to my project, I want to start implementing all these features in my own programs.