Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -1,20 +0,0 @@
generic
type Element_Type is private;
package Fifo is
type Fifo_Type is private;
procedure Push(List : in out Fifo_Type; Item : in Element_Type);
procedure Pop(List : in out Fifo_Type; Item : out Element_Type);
function Is_Empty(List : Fifo_Type) return Boolean;
Empty_Error : exception;
private
type Fifo_Element;
type Fifo_Ptr is access Fifo_Element;
type Fifo_Type is record
Head : Fifo_Ptr := null;
Tail : Fifo_Ptr := null;
end record;
type Fifo_Element is record
Value : Element_Type;
Next : Fifo_Ptr := null;
end record;
end Fifo;

View file

@ -1,11 +0,0 @@
generic
type Element_Type is private;
package Asynchronous_Fifo is
protected type Fifo is
procedure Push(Item : Element_Type);
entry Pop(Item : out Element_Type);
private
Value : Element_Type;
Valid : Boolean := False;
end Fifo;
end Asynchronous_Fifo;

View file

@ -1,30 +0,0 @@
package body Asynchronous_Fifo is
----------
-- Fifo --
----------
protected body Fifo is
----------
-- Push --
----------
procedure Push (Item : Element_Type) is
begin
Value := Item;
Valid := True;
end Push;
---------
-- Pop --
---------
entry Pop (Item : out Element_Type) when Valid is
begin
Item := Value;
end Pop;
end Fifo;
end Asynchronous_Fifo;

View file

@ -1,48 +0,0 @@
with Asynchronous_Fifo;
with Ada.Text_Io; use Ada.Text_Io;
procedure Asynchronous_Fifo_Test is
package Int_Fifo is new Asynchronous_Fifo(Integer);
use Int_Fifo;
Buffer : Fifo;
task Writer is
entry Stop;
end Writer;
task body Writer is
Val : Positive := 1;
begin
loop
select
accept Stop;
exit;
else
Buffer.Push(Val);
Val := Val + 1;
end select;
end loop;
end Writer;
task Reader is
entry Stop;
end Reader;
task body Reader is
Val : Positive;
begin
loop
select
accept Stop;
exit;
else
Buffer.Pop(Val);
Put_Line(Integer'Image(Val));
end select;
end loop;<syntaxhighlight lang="ada">
end Reader;
begin
delay 0.1;
Writer.Stop;
Reader.Stop;
end Asynchronous_Fifo_Test;

View file

@ -1,49 +0,0 @@
with Ada.Unchecked_Deallocation;
package body Fifo is
----------
-- Push --
----------
procedure Push (List : in out Fifo_Type; Item : in Element_Type) is
Temp : Fifo_Ptr := new Fifo_Element'(Item, null);
begin
if List.Tail = null then
List.Tail := Temp;
end if;
if List.Head /= null then
List.Head.Next := Temp;
end if;
List.Head := Temp;
end Push;
---------
-- Pop --
---------
procedure Pop (List : in out Fifo_Type; Item : out Element_Type) is
procedure Free is new Ada.Unchecked_Deallocation(Fifo_Element, Fifo_Ptr);
Temp : Fifo_Ptr := List.Tail;
begin
if List.Head = null then
raise Empty_Error;
end if;
Item := List.Tail.Value;
List.Tail := List.Tail.Next;
if List.Tail = null then
List.Head := null;
end if;
Free(Temp);
end Pop;
--------------
-- Is_Empty --
--------------
function Is_Empty (List : Fifo_Type) return Boolean is
begin
return List.Head = null;
end Is_Empty;
end Fifo;

View file

@ -1,17 +0,0 @@
with Fifo;
with Ada.Text_Io; use Ada.Text_Io;
procedure Fifo_Test is
package Int_Fifo is new Fifo(Integer);
use Int_Fifo;
My_Fifo : Fifo_Type;
Val : Integer;
begin
for I in 1..10 loop
Push(My_Fifo, I);
end loop;
while not Is_Empty(My_Fifo) loop
Pop(My_Fifo, Val);
Put_Line(Integer'Image(Val));
end loop;
end Fifo_Test;

View file

@ -1,13 +0,0 @@
with Ada.Containers.Doubly_Linked_Lists;
generic
type Element_Type is private;
package Generic_Fifo is
type Fifo_Type is tagged private;
procedure Push(The_Fifo : in out Fifo_Type; Item : in Element_Type);
procedure Pop(The_Fifo : in out Fifo_Type; Item : out Element_Type);
Empty_Error : Exception;
private
package List_Pkg is new Ada.Containers.Doubly_Linked_Lists(Element_Type);
use List_Pkg;
Type Fifo_Type is new List with null record;
end Generic_Fifo;

View file

@ -1,25 +0,0 @@
package body Generic_Fifo is
----------
-- Push --
----------
procedure Push (The_Fifo : in out Fifo_Type; Item : in Element_Type) is
begin
The_Fifo.Prepend(Item);
end Push;
---------
-- Pop --
---------
procedure Pop (The_Fifo : in out Fifo_Type; Item : out Element_Type) is
begin
if Is_Empty(The_Fifo) then
raise Empty_Error;
end if;
Item := The_Fifo.Last_Element;
The_Fifo.Delete_Last;
end Pop;
end Generic_Fifo;

View file

@ -1,17 +0,0 @@
with Generic_Fifo;
with Ada.Text_Io; use Ada.Text_Io;
procedure Generic_Fifo_Test is
package Int_Fifo is new Generic_Fifo(Integer);
use Int_Fifo;
My_Fifo : Fifo_Type;
Val : Integer;
begin
for I in 1..10 loop
My_Fifo.Push(I);
end loop;
while not My_Fifo.Is_Empty loop
My_Fifo.Pop(Val);
Put_Line(Integer'Image(Val));
end loop;
end Generic_Fifo_Test;

View file

@ -1,11 +0,0 @@
generic
type Element_Type is private;
package Synchronous_Fifo is
protected type Fifo is
entry Push(Item : Element_Type);
entry Pop(Item : out Element_Type);
private
Value : Element_Type;
Is_New : Boolean := False;
end Fifo;
end Synchronous_Fifo;

View file

@ -1,31 +0,0 @@
package body Synchronous_Fifo is
----------
-- Fifo --
----------
protected body Fifo is
---------
-- Push --
---------
entry Push (Item : Element_Type) when not Is_New is
begin
Value := Item;
Is_New := True;
end Push;
---------
-- Pop --
---------
entry Pop (Item : out Element_Type) when Is_New is
begin
Item := Value;
Is_New := False;
end Pop;
end Fifo;
end Synchronous_Fifo;

View file

@ -1,56 +0,0 @@
with Synchronous_Fifo;
with Ada.Text_Io; use Ada.Text_Io;
procedure Synchronous_Fifo_Test is
package Int_Fifo is new Synchronous_Fifo(Integer);
use Int_Fifo;
Buffer : Fifo;
task Writer is
entry Stop;
end Writer;
task body Writer is
Val : Positive := 1;
begin
loop
select
accept Stop;
exit;
else
select
Buffer.Push(Val);
Val := Val + 1;
or
delay 1.0;
end select;
end select;
end loop;
end Writer;
task Reader is
entry Stop;
end Reader;
task body Reader is
Val : Positive;
begin
loop
select
accept Stop;
exit;
else
select
Buffer.Pop(Val);
Put_Line(Integer'Image(Val));
or
delay 1.0;
end select;
end select;
end loop;
end Reader;
begin
delay 0.1;
Writer.Stop;
Reader.Stop;
end Synchronous_Fifo_Test;

View file

@ -1,21 +1,21 @@
define :queue [][
init: [
define :queue [
init: method [][
this\items: []
]
]
empty?: function [this :queue][
zero? this\items
]
empty?: method [][
zero? this\items
]
push: function [this :queue, item][
this\items: this\items ++ item
]
push: method [item][
this\items: this\items ++ item
]
pop: function [this :queue][
ensure -> not? empty? this
pop: method [][
ensure -> [not? this\empty?]
result: this\items\0
this\items: remove.index this\items 0
return result
result: this\items\0
this\items: remove.index this\items 0
return result
]
]

View file

@ -1,6 +1,6 @@
import extensions;
class queue<T>
class Queue<T>
{
T[] theArray;
int theTop;
@ -20,7 +20,10 @@ class queue<T>
{
if (theTale > theArray.Length)
{
theArray := theArray.reallocate(theTale)
auto newArray := class Array<T>.allocate(theTale);
class Array<T>.copy(newArray, theArray, 0, theArray.Length);
theArray := newArray
};
theArray[theTale] := object;
@ -41,23 +44,23 @@ class queue<T>
}
}
public program()
public Program()
{
queue<int> q := new queue<int>();
Queue<int> q := new Queue<int>();
q.push(1);
q.push(2);
q.push(3);
console.printLine(q.pop());
console.printLine(q.pop());
console.printLine(q.pop());
console.printLine("a queue is ", q.empty().iif("empty","not empty"));
console.print("Trying to pop:");
Console.printLine(q.pop());
Console.printLine(q.pop());
Console.printLine(q.pop());
Console.printLine("a queue is ", q.empty().iif("empty","not empty"));
Console.print("Trying to pop:");
try
{
q.pop()
}
catch(Exception e)
{
console.printLine(e.Message)
Console.printLine(e.Message)
}
}

View file

@ -1,17 +0,0 @@
$Q = New-Object System.Collections.Queue
$Q.Enqueue( 1 )
$Q.Enqueue( 2 )
$Q.Enqueue( 3 )
$Q.Dequeue()
$Q.Dequeue()
$Q.Count -eq 0
$Q.Dequeue()
$Q.Count -eq 0
try
{ $Q.Dequeue() }
catch [System.InvalidOperationException]
{ If ( $_.Exception.Message -eq 'Queue empty.' ) { 'Caught error' } }

View file

@ -1,31 +0,0 @@
rebol [
Title: "FIFO"
URL: http://rosettacode.org/wiki/FIFO
]
; Define fifo class:
fifo: make object! [
queue: copy []
push: func [x][append queue x]
pop: func [/local x][ ; Make 'x' local so it won't pollute global namespace.
if empty [return none]
x: first queue remove queue x]
empty: does [empty? queue]
]
; Create and populate a FIFO:
q: make fifo []
q/push 'a
q/push 2
q/push USD$12.34 ; Did I mention that REBOL has 'money!' datatype?
q/push [Athos Porthos Aramis] ; List elements pushed on one by one.
q/push [[Huey Dewey Lewey]] ; This list is preserved as a list.
; Dump it out, with narrative:
print rejoin ["Queue is " either q/empty [""]["not "] "empty."]
while [not q/empty][print [" " q/pop]]
print rejoin ["Queue is " either q/empty [""]["not "] "empty."]
print ["Trying to pop an empty queue yields:" q/pop]

View file

@ -1,37 +0,0 @@
' Queue Definition - VBScript
Option Explicit
Dim queue, i, x
Set queue = CreateObject("System.Collections.ArrayList")
If Not empty_(queue) Then Wscript.Echo queue.Count
push queue, "Banana"
push queue, "Apple"
push queue, "Pear"
push queue, "Strawberry"
Wscript.Echo "Count=" & queue.Count
Wscript.Echo pull(queue) & " - Count=" & queue.Count '
Wscript.Echo "Head=" & queue.Item(0)
Wscript.Echo "Tail=" & queue.Item(queue.Count-1)
Wscript.Echo queue.IndexOf("Pear", 0)
For i=1 To queue.Count
Wscript.Echo join(queue.ToArray(), ", ")
x = pull(queue)
Next 'i
Sub push(q, what)
q.Add what
End Sub 'push
Function pull(q)
Dim what
If q.Count > 0 Then
what = q(0)
q.RemoveAt 0
Else
what = ""
End If
pull = what
End Function 'pull
Function empty_(q)
empty_ = q.Count = 0
End Function 'empty_