Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,32 +0,0 @@
|
|||
generic
|
||||
type Element_Type is private;
|
||||
with function To_String (E : Element_Type) return String is <>;
|
||||
package Nestable_Lists is
|
||||
|
||||
type Node_Kind is (Data_Node, List_Node);
|
||||
|
||||
type Node (Kind : Node_Kind);
|
||||
|
||||
type List is access Node;
|
||||
|
||||
type Node (Kind : Node_Kind) is record
|
||||
Next : List;
|
||||
case Kind is
|
||||
when Data_Node =>
|
||||
Data : Element_Type;
|
||||
when List_Node =>
|
||||
Sublist : List;
|
||||
end case;
|
||||
end record;
|
||||
|
||||
procedure Append (L : in out List; E : Element_Type);
|
||||
procedure Append (L : in out List; N : List);
|
||||
|
||||
function Flatten (L : List) return List;
|
||||
|
||||
function New_List (E : Element_Type) return List;
|
||||
function New_List (N : List) return List;
|
||||
|
||||
function To_String (L : List) return String;
|
||||
|
||||
end Nestable_Lists;
|
||||
|
|
@ -1,79 +0,0 @@
|
|||
with Ada.Strings.Unbounded;
|
||||
|
||||
package body Nestable_Lists is
|
||||
|
||||
procedure Append (L : in out List; E : Element_Type) is
|
||||
begin
|
||||
if L = null then
|
||||
L := new Node (Kind => Data_Node);
|
||||
L.Data := E;
|
||||
else
|
||||
Append (L.Next, E);
|
||||
end if;
|
||||
end Append;
|
||||
|
||||
procedure Append (L : in out List; N : List) is
|
||||
begin
|
||||
if L = null then
|
||||
L := new Node (Kind => List_Node);
|
||||
L.Sublist := N;
|
||||
else
|
||||
Append (L.Next, N);
|
||||
end if;
|
||||
end Append;
|
||||
|
||||
function Flatten (L : List) return List is
|
||||
Result : List;
|
||||
Current : List := L;
|
||||
Temp : List;
|
||||
begin
|
||||
while Current /= null loop
|
||||
case Current.Kind is
|
||||
when Data_Node =>
|
||||
Append (Result, Current.Data);
|
||||
when List_Node =>
|
||||
Temp := Flatten (Current.Sublist);
|
||||
while Temp /= null loop
|
||||
Append (Result, Temp.Data);
|
||||
Temp := Temp.Next;
|
||||
end loop;
|
||||
end case;
|
||||
Current := Current.Next;
|
||||
end loop;
|
||||
return Result;
|
||||
end Flatten;
|
||||
|
||||
function New_List (E : Element_Type) return List is
|
||||
begin
|
||||
return new Node'(Kind => Data_Node, Data => E, Next => null);
|
||||
end New_List;
|
||||
|
||||
function New_List (N : List) return List is
|
||||
begin
|
||||
return new Node'(Kind => List_Node, Sublist => N, Next => null);
|
||||
end New_List;
|
||||
|
||||
function To_String (L : List) return String is
|
||||
Current : List := L;
|
||||
Result : Ada.Strings.Unbounded.Unbounded_String;
|
||||
begin
|
||||
Ada.Strings.Unbounded.Append (Result, "[");
|
||||
while Current /= null loop
|
||||
case Current.Kind is
|
||||
when Data_Node =>
|
||||
Ada.Strings.Unbounded.Append
|
||||
(Result, To_String (Current.Data));
|
||||
when List_Node =>
|
||||
Ada.Strings.Unbounded.Append
|
||||
(Result, To_String (Current.Sublist));
|
||||
end case;
|
||||
if Current.Next /= null then
|
||||
Ada.Strings.Unbounded.Append (Result, ", ");
|
||||
end if;
|
||||
Current := Current.Next;
|
||||
end loop;
|
||||
Ada.Strings.Unbounded.Append (Result, "]");
|
||||
return Ada.Strings.Unbounded.To_String (Result);
|
||||
end To_String;
|
||||
|
||||
end Nestable_Lists;
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
with Ada.Text_IO;
|
||||
with Nestable_Lists;
|
||||
|
||||
procedure Flatten_A_List is
|
||||
package Int_List is new Nestable_Lists
|
||||
(Element_Type => Integer,
|
||||
To_String => Integer'Image);
|
||||
|
||||
List : Int_List.List := null;
|
||||
begin
|
||||
Int_List.Append (List, Int_List.New_List (1));
|
||||
Int_List.Append (List, 2);
|
||||
Int_List.Append (List, Int_List.New_List (Int_List.New_List (3)));
|
||||
Int_List.Append (List.Next.Next.Sublist.Sublist, 4);
|
||||
Int_List.Append (List.Next.Next.Sublist, 5);
|
||||
Int_List.Append (List, Int_List.New_List (Int_List.New_List (null)));
|
||||
Int_List.Append (List, Int_List.New_List (Int_List.New_List
|
||||
(Int_List.New_List (6))));
|
||||
Int_List.Append (List, 7);
|
||||
Int_List.Append (List, 8);
|
||||
Int_List.Append (List, null);
|
||||
|
||||
declare
|
||||
Flattened : constant Int_List.List := Int_List.Flatten (List);
|
||||
begin
|
||||
Ada.Text_IO.Put_Line (Int_List.To_String (List));
|
||||
Ada.Text_IO.Put_Line (Int_List.To_String (Flattened));
|
||||
end;
|
||||
end Flatten_A_List;
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
(defun flatten (mylist)
|
||||
(cond
|
||||
((null mylist) nil)
|
||||
((atom mylist) (list mylist))
|
||||
(t
|
||||
(append (flatten (car mylist)) (flatten (cdr mylist))))))
|
||||
|
|
@ -1 +0,0 @@
|
|||
(flatten-tree mylist)
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
sequence a = {{1}, 2, {{3, 4}, 5}, {{{}}}, {{{6}}}, 7, 8, {}}
|
||||
|
||||
function flatten( object s )
|
||||
sequence res = {}
|
||||
if sequence( s ) then
|
||||
for i = 1 to length( s ) do
|
||||
sequence c = flatten( s[ i ] )
|
||||
if length( c ) > 0 then
|
||||
res &= c
|
||||
end if
|
||||
end for
|
||||
else
|
||||
if length( s ) > 0 then
|
||||
res = { s }
|
||||
end if
|
||||
end if
|
||||
return res
|
||||
end function
|
||||
|
||||
? a
|
||||
? flatten(a)
|
||||
|
|
@ -1 +1,3 @@
|
|||
?flatten({{1},2,{{3,4},5},{{{}}},{{{6}}},7,8,{}})
|
||||
(phixonline)(not pygments)-->
|
||||
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">flatten</span><span style="color: #0000FF;">({{</span><span style="color: #000000;">1</span><span style="color: #0000FF;">},</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,{{</span><span style="color: #000000;">3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">4</span><span style="color: #0000FF;">},</span><span style="color: #000000;">5</span><span style="color: #0000FF;">},{{{}}},{{{</span><span style="color: #000000;">6</span><span style="color: #0000FF;">}}},</span><span style="color: #000000;">7</span><span style="color: #0000FF;">,</span><span style="color: #000000;">8</span><span style="color: #0000FF;">,{}})</span>
|
||||
<!--
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
function flatten($a) {
|
||||
if($a.Count -gt 1) {
|
||||
$a | foreach{ $(flatten $_)}
|
||||
} else {$a}
|
||||
}
|
||||
$a = @(@(1), 2, @(@(3,4), 5), @(@(@())), @(@(@(6))), 7, 8, @())
|
||||
"$(flatten $a)"
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
flatten: func [
|
||||
"Flatten the block in place."
|
||||
block [any-block!]
|
||||
][
|
||||
parse block [
|
||||
any [block: any-block! (change/part block first block 1) :block | skip]
|
||||
]
|
||||
head block
|
||||
]
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
class flattener
|
||||
dim separator
|
||||
|
||||
sub class_initialize
|
||||
separator = ","
|
||||
end sub
|
||||
|
||||
private function makeflat( a )
|
||||
dim i
|
||||
dim res
|
||||
for i = lbound( a ) to ubound( a )
|
||||
if isarray( a( i ) ) then
|
||||
res = res & makeflat( a( i ) )
|
||||
else
|
||||
res = res & a( i ) & separator
|
||||
end if
|
||||
next
|
||||
makeflat = res
|
||||
end function
|
||||
|
||||
public function flatten( a )
|
||||
dim res
|
||||
res = makeflat( a )
|
||||
res = left( res, len( res ) - len(separator))
|
||||
res = split( res, separator )
|
||||
flatten = res
|
||||
end function
|
||||
|
||||
public property let itemSeparator( c )
|
||||
separator = c
|
||||
end property
|
||||
end class
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
dim flat
|
||||
set flat = new flattener
|
||||
flat.itemSeparator = "~"
|
||||
wscript.echo join( flat.flatten( array( array( 1 ),2,array(array(3,4),5),array(array(array())),array(array(array(6))),7,8,array())), "!")
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
' Flatten the example array...
|
||||
a = FlattenArray(Array(Array(1), 2, Array(Array(3,4), 5), Array(Array(Array())), Array(Array(Array(6))), 7, 8, Array()))
|
||||
|
||||
' Print the list, comma-separated...
|
||||
WScript.Echo Join(a, ",")
|
||||
|
||||
Function FlattenArray(a)
|
||||
If IsArray(a) Then DoFlatten a, FlattenArray: FlattenArray = Split(Trim(FlattenArray))
|
||||
End Function
|
||||
|
||||
Sub DoFlatten(a, s)
|
||||
For i = 0 To UBound(a)
|
||||
If IsArray(a(i)) Then DoFlatten a(i), s Else s = s & a(i) & " "
|
||||
Next
|
||||
End Sub
|
||||
Loading…
Add table
Add a link
Reference in a new issue