From cdee2439d8163c663346894b28d68b976b1b7207 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 17 Mar 2010 19:13:25 +1300 Subject: [PATCH] grouping: minor cleanup --- basis/grouping/authors.txt | 1 + basis/grouping/grouping.factor | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/basis/grouping/authors.txt b/basis/grouping/authors.txt index 1901f27a24..580f882c8d 100644 --- a/basis/grouping/authors.txt +++ b/basis/grouping/authors.txt @@ -1 +1,2 @@ Slava Pestov +Joe Groff diff --git a/basis/grouping/grouping.factor b/basis/grouping/grouping.factor index 304fd50fcc..1a7e267c90 100644 --- a/basis/grouping/grouping.factor +++ b/basis/grouping/grouping.factor @@ -1,8 +1,7 @@ -! Copyright (C) 2005, 2010 Slava Pestov. +! Copyright (C) 2005, 2010 Slava Pestov, Joe Groff. ! See http://factorcode.org/license.txt for BSD license. USING: kernel math math.order strings arrays vectors sequences -sequences.private accessors fry combinators.short-circuit -combinators ; +sequences.private accessors fry combinators ; IN: grouping = [ - ] [ drop ] if ; inline : check-circular-clumps ( seq n -- seq n ) - 2dup { [ nip 0 <= ] [ swap length > ] } 2|| - [ "Invalid clump size" throw ] when ; inline + 2dup 1 - swap bounds-check 2drop ; inline PRIVATE> @@ -115,15 +113,18 @@ INSTANCE: sliced-clumps abstract-clumps : all-eq? ( seq -- ? ) [ eq? ] monotonic? ; -TUPLE: circular-slice - { from read-only } - { to read-only } - { seq read-only } ; +TUPLE: circular-slice { from read-only } { to read-only } { seq read-only } ; + INSTANCE: circular-slice virtual-sequence + M: circular-slice equal? over slice? [ sequence= ] [ 2drop f ] if ; + M: circular-slice hashcode* [ sequence-hashcode ] recursive-hashcode ; + M: circular-slice length [ to>> ] [ from>> ] bi - ; inline + M: circular-slice virtual-exemplar seq>> ; inline + M: circular-slice virtual@ [ from>> + ] [ seq>> ] bi [ length slice-mod ] keep ; inline @@ -155,4 +156,3 @@ M: circular-clumps nth : circular-clump ( seq n -- array ) { } like ; inline -