diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0ae7547 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +Copyright (c) 2010, TEAM CTHULHU +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +Neither the name of the TEAM CTHULHU nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..209498e --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +all: + cd seq && gomake + +install: + cd seq && gomake install diff --git a/calc/LICENSE b/calc/LICENSE index 8631e77..0ae7547 100644 --- a/calc/LICENSE +++ b/calc/LICENSE @@ -1,22 +1,9 @@ - version 1.2.2, October 3rd, 2004 +Copyright (c) 2010, TEAM CTHULHU +All rights reserved. - Copyright (C) 1995-2004 Jean-loup Gailly and Mark Adler +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly jloup@gzip.org - Mark Adler madler@alumni.caltech.edu +Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +Neither the name of the TEAM CTHULHU nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/calc/calcgo b/calc/calcgo index cd6335b..424a36e 100755 --- a/calc/calcgo +++ b/calc/calcgo @@ -26,15 +26,25 @@ while (line=`{read}) { cat < $script package main import . "fmt" +here +if (grep '//BODY' $file > /dev/null) { + awk '/\/\/BODY/{exit}skipped{print}!skipped{skipped=1}' < $file >> $script +} +cat <> $script func main() { here while (! ~ $#* 0) { echo (' '$1^' := float64('$2')') >> $script shift 2 } -<$file{ -read>/dev/null -cat >> $script +if (grep '//BODY' $file > /dev/null) { + awk 'yes{print}/\/\/BODY/{yes=1}' < $file >> $script +} +if not { + <$file{ + read>/dev/null + cat >> $script + } } cat<> $script func() { diff --git a/seq/LICENSE b/seq/LICENSE new file mode 100644 index 0000000..0ae7547 --- /dev/null +++ b/seq/LICENSE @@ -0,0 +1,9 @@ +Copyright (c) 2010, TEAM CTHULHU +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +Neither the name of the TEAM CTHULHU nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/seq/seq.go b/seq/seq.go index a78e7f8..0d0ab33 100644 --- a/seq/seq.go +++ b/seq/seq.go @@ -103,7 +103,7 @@ func IsEmpty(s Seq) bool { return empty } -//returns the first item in a sequence for which f returns true +//returns the first item in a sequence for which f returns true or nil if none is found func Find(s Seq, f func(el El) bool) El {return s.Find(f)} //applies f to each item in the sequence until f returns false @@ -117,9 +117,9 @@ func Do(s Seq, f func(el El)) { }) } -//applies f concurrently to each element of s, in no particular order -func CDo(s Seq, f func(el El)) { - c := CMap(s, func(el El)El{f(el); return nil})() +//applies f concurrently to each element of s, in no particular order; sizePowerOpt will default to {6} and CMap will allow up to 1 << sizePowerOpt[0] outstanding concurrent instances of f at any time +func CDo(s Seq, f func(el El), sizePowerOpt... uint) { + c := CMap(s, func(el El)El{f(el); return nil}, sizePowerOpt...)() for <- c; !closed(c); <- c {} } @@ -177,10 +177,10 @@ func SFilter(s Seq, filter func(e El)bool) *SequentialSeq { return (*SequentialSeq)(&vec) } -//returns a new ConcurrentSeq consisting of the elements of s for which filter returns true -func CFilter(s Seq, filter func(e El)bool) ConcurrentSeq { +//returns a new ConcurrentSeq consisting of the elements of s for which filter returns true; sizePowerOpt will default to {6} and CMap will allow up to 1 << sizePowerOpt[0] outstanding concurrent instances of f at any time +func CFilter(s Seq, filter func(e El)bool, sizePowerOpt... uint) ConcurrentSeq { return Gen(func(c SeqChan){ - Do(s, ifFunc(filter, func(el El){c <- el})) + Do(s, ifFunc(filter, func(el El){c <- el}), sizePowerOpt...) }) } @@ -253,7 +253,7 @@ func (r *SlidingWindow) Set(index int, value interface{}) bool { return true } -//returns a new ConcurrentSeq consisting of the results of appying f to the elements of s +//returns a new ConcurrentSeq consisting of the results of appying f to the elements of s; sizePowerOpt will default to {6} and CMap will allow up to 1 << sizePowerOpt[0] outstanding concurrent instances of f at any time func CMap(s Seq, f func(el El) El, sizePowerOpt... uint) ConcurrentSeq { // spawn a goroutine that does the following for each value, with up to size pending at a time: // spawn a goroutine to apply f to the value and send the result back in a channel @@ -309,10 +309,10 @@ func SFlatMap(s Seq, f func(i El) Seq) *SequentialSeq { return (*SequentialSeq)(&vec) } -//returns a new ConcurrentSeq consisting of the concatenation of the sequences f returns when applied to all of the elements of s -func CFlatMap(s Seq, f func(i El) Seq, sizeOpt... uint) ConcurrentSeq { +//returns a new ConcurrentSeq consisting of the concatenation of the sequences f returns when applied to all of the elements of s; sizePowerOpt will default to {6} and CMap will allow up to 1 << sizePowerOpt[0] outstanding concurrent instances of f at any time +func CFlatMap(s Seq, f func(i El) Seq, sizePowerOpt... uint) ConcurrentSeq { return Gen(func(c SeqChan){ - Do(CMap(s, func(e El)El{return f(e)}, sizeOpt...), func(sub El){ + Do(CMap(s, func(e El)El{return f(e)}, sizePowerOpt...), func(sub El){ Output(sub.(Seq), c) }) }) @@ -432,7 +432,7 @@ func CUpto(limit int) ConcurrentSeq { }) } -//returns the first item in a sequence for which f returns true +//returns the first item in a sequence for which f returns true or nil if none is found func (s ConcurrentSeq) Find(f func(el El)bool) El { c := s() defer close(c) @@ -500,7 +500,7 @@ func AUpto(limit int) *SequentialSeq { return (*SequentialSeq)(&a) } -//returns the first item in a sequence for which f returns true +//returns the first item in a sequence for which f returns true or nil if none is found func (s *SequentialSeq) Find(f func(el El)bool) El { for i := 0; i < len(*s); i++ { if f((*s)[i]) {return (*s)[i]}