8.18
top
← prev up next →

Double Linked RingπŸ”— i

Matteo d'Addio <matteo.daddio@live.it>

A double linked ring data structure. A ring has no beginning or end, it only has a current element.

procedure

( ring? buff)boolean?

buff:any/c
Determines if buff is a ring buffer.

procedure

( ring [a-list])ring?

a-list:'()=list?
Create a ring from a list. If the list isn’t specified an empty ring is created. The current element of the ring is set to the first element of the list.

procedure

( ring->list a-ring)list?

a-ring:ring?
Creates a list of the element in the ring starting from the current one.

Examples:
> (define the-ring(ring '(abcd)))
> (ring->list the-ring)

'(a b c d)

procedure

( ring-size a-ring)exact-nonnegative-integer?

a-ring:ring?
Returns the number of elements of the ring.

procedure

( ring-current a-ring)any/c

a-ring:ring?
Returns the current element of the ring. If the ring is empty an exception is raised.

Examples:
> (define the-ring(ring ))
> (ring-size the-ring)

0

> (ring-current the-ring)

ring-current: the ring is empty

> (define the-ring(ring '(abcd)))
> (ring-size the-ring)

4

> (ring-current the-ring)

'a

procedure

( ring-next! a-ring)any/c

a-ring:ring?
Returns the next element of the ring and sets the current element to this element. If the ring is empty an exception is raised.

procedure

( ring-prev! a-ring)any/c

a-ring:ring?
Returns the previous element of the ring and sets the current element to this element. If the ring is empty an exception is raised.

Examples:
> (define the-ring(ring '(abcd)))
> (ring-current the-ring)

'a

> (ring-next! the-ring)

'b

> (ring-current the-ring)

'b

> (ring->list the-ring)

'(b c d a)

> (ring-prev! the-ring)

'a

> (ring-prev! the-ring)

'd

> (ring-current the-ring)

'd

> (ring->list the-ring)

'(d a b c)

procedure

( ring-remove-current! a-ring)void?

a-ring:ring?
Removes the current element of the ring and sets the current element to the next element. If the ring is empty an exception is raised.

procedure

( ring-set-current! a-ringelem)void?

a-ring:ring?
elem:any/c
Sets the current element to elem with set! . If the ring is empty an exception is raised.

Examples:
> (define the-ring(ring '(abcd)))
> (ring-set-current! the-ring'A)
> (ring->list the-ring)

'(A b c d)

> (ring-remove-current! the-ring)
> (ring->list the-ring)

'(b c d)

procedure

( ring-add-next! a-ringelem)void?

a-ring:ring?
elem:any/c
Adds a new elem after the current one and sets the new elem as current.

procedure

( ring-add-prev! a-ringelem)void?

a-ring:ring?
elem:any/c
Adds a new elem before the current one and sets the new elem as current.

Examples:
> (define the-ring(ring '(abcd)))
> (ring-add-prev! the-ring1)
> (ring-add-prev! the-ring2)
> (ring-add-prev! the-ring3)
> (ring->list the-ring)

'(3 2 1 a b c d)

> (set! the-ring(ring '(abcd)))
> (ring-add-next! the-ring1)
> (ring-add-next! the-ring2)
> (ring-add-next! the-ring3)
> (ring->list the-ring)

'(3 b c d a 1 2)

The procedure ring->list can be quite confusing. I use it mainly for debugging purposes.

top
← prev up next →

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /