HeirOfNorton's Vector Class module

Started by HeirOfNorton, Mon 03/07/2006 04:38:41

Previous topic - Next topic

HeirOfNorton

Hey folks, just a little helper if anyone wants it. It occurred to me that most of the functionality needed for a vector (or a dynamic array, if you prefer) already existed in AGS in the form of the new String class, so I whipped this here up.

This is a vector class for integers. At this time it does not work with any other data type. I have not included separate documentation, but the module header is fully commented with usage and the API.

I'm not really sure how useful this will be. I mainly did it as coding practice, but I figured it could be useful to anyone who really needs a dynamic array, at least until CJ gets around to implementing the real thing.

You can download it HERE.

HoN

jasonjkay

Sounds great, i'll add it to my webpage soon.
http://www.americangirlscouts.org/agsresources/ - Mods, plugins and templates.

subspark

#2
Has someone already come up with a generic Vector Module for all known classes and types?
I'm rather excited about this.

monkey0506

#3
Vectors are dynamically sized arrays. HON said that. But that's what it is.

Say for example, you want to gather a set of user input, but you don't know how big it's going to be.  You could (a) set a large limit and create an array which if not completely filled will waste space but cannot increase in size if more space is needed, or (b) use a vector to create a dynamic array, storing all the data the user inputs.

For example, as a make-up project for my seminary class last school year, I used AGS to make a very simple program to place the 20 students into 3 groups randomly. Supposing we had gained more students, and had I used a vector in designing the program and made it so new students could be added and students could be removed...it would be easier to just allow the user to increase the size of the array (vector) rather than having to recompile...considering when I made it I only made it with the 20 spaces for the 20 existing students.

Not entirely sure if that helps at all...may have made it worse...but then I seem to like sleep deprivation because I apparently hate sleeping.

There's no generic vector module yet, although all three could be combined into one...

DoorKnobHandle

I suggest renaming the module to "dynamically sized array-module" or something the like, because most people think of vectors as those arrow-like objects in maths.

strazer

#5
Most of the time I use #defines when specifiying array dimensions, so I just have to change a single definition in the header. I probably just don't get it since I don't see a benefit for me personally.

Anyway, I would appreciate it if someone combined these modules into one before this goes to the Tech Archive.

Also, people, please always specifiy what AGS version is the minimum requirement! Using modules with the wrong AGS version confuses users and produces unnecessary error reports.

Edit:

Thanks, monkey!

Alright, all further discussion regarding monkey_05_06's modules in this thread.

monkey0506

#6
@dkh:

Vector is the name given to dynamically-sized arrays by languages like C++...

@strazer:

I've combined the modules, and I'll add notices for version requirements.

[EDIT:]

Also, strazer, vectors are useful when you don't know the size of array demanded. You can't create a #define based on a variable so the alternative in this situation would be creating a very large array, or limiting the size of the array.

With vectors you don't have to worry about setting the size as it can change dynamically as needed.

They can also save memory if you use a vector instead of a large array that may not be entirely used...

Of course I'm repeating myself.  So...I'm going to stop now.

SMF spam blocked by CleanTalk