name of data structure for circular array?

B

Bob Jenkins

I have this cute data structure that I just found a second opportunity
to use. I googled for references to it, but came up empty. I
probably just don't know its name.

The algorithm on this data structure typically has an array of
pointers, and in a loop refers to array[i % n] .. array[(i+n-1) % n],
modifies array[i % n], then increments i. I do away with i by having
an array of size 2*n, where array = array[i+n]. Then I use array2
instead of array, increment array2 instead of i, and reference
array2[0]..array2[n-1]. The loop has to remember to reset array2
whenever it walks too far, but otherwise i and %n are gone.

What's this data structure called? Where is it used?
 
E

E. Robert Tisdale

Bob said:
I have this cute data structure that I just found a second opportunity
to use. I googled for references to it, but came up empty. I
probably just don't know its name.

The algorithm on this data structure typically has an array of
pointers, and in a loop refers to array[i % n] .. array[(i+n-1) % n],
modifies array[i % n], then increments i. I do away with i by having
an array of size 2*n, where array = array[i+n]. Then I use array2
instead of array, increment array2 instead of i, and reference
array2[0]..array2[n-1]. The loop has to remember to reset array2
whenever it walks too far, but otherwise i and %n are gone.

What's this data structure called? Where is it used?


A "circular queue" or a "circular buffer".

I searched Google

http://www.google.com/

for

+"circular queue"

and I found lots of stuff.
 
T

Thomas Matthews

E. Robert Tisdale said:
Bob said:
I have this cute data structure that I just found a second opportunity
to use. I googled for references to it, but came up empty. I
probably just don't know its name.

The algorithm on this data structure typically has an array of
pointers, and in a loop refers to array[i % n] .. array[(i+n-1) % n],
modifies array[i % n], then increments i. I do away with i by having
an array of size 2*n, where array = array[i+n]. Then I use array2
instead of array, increment array2 instead of i, and reference
array2[0]..array2[n-1]. The loop has to remember to reset array2
whenever it walks too far, but otherwise i and %n are gone.

What's this data structure called? Where is it used?



A "circular queue" or a "circular buffer".

I searched Google

http://www.google.com/

for

+"circular queue"

and I found lots of stuff.


This is also known as a ring buffer.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top