view list.rhope @ 73:6a1a7d5cc2d9

Add some error checking, cleanup output and add a bad test file
author Mike Pavone <pavone@retrodev.com>
date Sat, 19 Jun 2010 23:13:41 -0400
parents 1bfcf5f8fa69
children 0083b2f7b3c7
line wrap: on
line source


Blueprint List Leaf
{
	Buffer
}

Index@List Leaf[list,index:out,not found]
{
	out, not found <- [[list]Buffer >>]Index[index]
}

Set@List Leaf[list,index,value:out]
{
	If[[index] < [0]]
	{
	}{
		If[[index] > [[[list]Buffer >>]Length >>]]
		{
			makeleft <- Yes
		}{
			If[[index] > [7]]
			{
				makeleft <- Yes
			}{
				out <- [list]Buffer <<[ [[list]Buffer >>]Set[index, value] ]
			}
		}
	}

	Val[makeleft]
	{
		out <- [[[[[[Build[List()]
			]Buffer << [[Array[]]Append[value]]
			]Left << [list]
			]Right << [List[]]
			]Offset << [index]
			]Right Offset <<[[index]+[8i32]]
			]Length << [ [[list]Length]+[1] ]
	}
}

Blueprint List
{
	Buffer
	Left
	Right
	Offset(Int32,Naked)
	Right Offset(Int32,Naked)
	Length(Int32,Naked)
}

List[:out(List)]
{
	out <- [Build[List Leaf()]]Buffer <<[Array[]]
}

Index@List[list,index:out,not found]
{
	If[[index]<[[list]Offset >>]]
	{
		out, not found <- [[list]Left >>]Index[index]
	}{
		If[[index] < [[list]Right Offset >>]]
		{
			out, not found <- [[list]Buffer >>]Index[[index]-[[list]Offset >>]]
		}{
			out, not found <- [[list]Right >>]Index[[index]-[[list]Right Offset >>]]
		}
	}
}

Set@List[list,index,val:out,not found]
{
	
}