Circular linked list  
Author Message
Sharp





PostPosted: 2005-3-5 17:35:00 Top

java-programmer, Circular linked list Hi

I'm looking for a circular linked list implementation.
Any references appreciated.

Cheers
Sharp


 
shakah





PostPosted: 2005-3-5 20:53:00 Top

java-programmer >> Circular linked list Do you mean a ring buffer? A quick google search for "Java ring buffer"
yielded http://www.jadetower.org/muses/archives/000124.html, excerpted
here:

class BlockingMessageBuffer {
Message[] messages = new Item[BUF_SIZ];
int hd = 0, tl = 0;

public synchronized void put(Message mess) {
messages[tl] = it;
++tl;
if (tl == messages.length) tl = 0;

if (tl == hd) waitIgnoringInterrupts();
notifyAll(); // Wakes all the threads that are waiting to get.
}

public synchronized Message get() {
if (hd == tl) waitIgnoringInterrupts();
notifyAll(); // Wakes all the threads that are waiting to put.

Message mess = messages[hd];
++hd;
if (hd == messages.length) hd = 0;
return mess;
}

private void waitIgnoringInterrupts() {
while (true) {
try {
wait(); // Puts the current thread to sleep and
// frees synchronization claims on this buffer.
return;
} catch (InterruptedException e) {}
}
}
}

 
John B. Matthews





PostPosted: 2005-3-5 22:21:00 Top

java-programmer >> Circular linked list In article <email***@***.com>,
"shakah" <email***@***.com> wrote:

> Do you mean a ring buffer? A quick google search for "Java ring buffer"
> yielded http://www.jadetower.org/muses/archives/000124.html, excerpted
> here:
> [...]
> public synchronized void put(Message mess) {
> messages[tl] = it;
> [...]

Perhaps the original author meant

public synchronized void put(Message mess) {
messages[tl] = mess;
--
John
jmatthews at wright dot edu
www dot wright dot edu/~john.matthews/
 
 
Thomas G. Marshall





PostPosted: 2005-3-6 5:21:00 Top

java-programmer >> Circular linked list Sharp coughed up:
> Hi
>
> I'm looking for a circular linked list implementation.
> Any references appreciated.
>
> Cheers
> Sharp


If you grow your own, be sure to read this quick thread about someone else
who had done the same, and met with trouble when trying to make it a List.

http://groups-beta.google.com/group/comp.lang.java.programmer/browse_frm/thread/a70ce691d6197c2c/ae7a3d9730ce86a6?q=java+circularlinkedlist#ae7a3d9730ce86a6


--
"So I just, uh... I just cut them up like regular chickens?"
"Sure, just cut them up like regular chickens."