What do I call this structure?

Started by
1 comment, last by rip-off 12 years, 5 months ago
Hello all,

There's a simple construct I often find myself using when programming ( after hearing about how to use it from somebody else ), but I have never known what to call it. It's basically a fixed-size array, with a "count" value that specifies how many items are in it. Whenever you add an item, it always goes on the end. Whenever you remove an item, you pull the item on the end off, and insert it into the hole created by the removed item ( unless the removed item was the end item ).

So it's pretty much just an orderless array, but it's super-useful for accumulation and "choose-one-but-guaranteed-no-repeats" randomness. Plus there's no allocation or copying required, so its very low overhead.

Is there a proper term for this thing? I have been calling it a "Bucket", but that hardly seems informative. I'd greatly appreciate any help with the terminology, and perhaps a more formal definition.

Thanks!
Advertisement
Unordered array is about as technical as the naming gets. However, if I'm understanding the statement "choose-one-but-guaranteed-no-repeats" correctly, you've restricted it to an unordered set. Whether your specific optimization technique has a name, I don't know, but you pretty much already know the name of the data structure you've described.
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
I'd call it a "bag", as I don't see how the implementation you've described guarantees no repeats. If you do guarantee no repeats, I would call it an unordered set. However, I'd probably also throw in the modifier "fixed" or "limited", as the container has a defined maximum size.

This topic is closed to new replies.

Advertisement