From 42f404787abb5cfc104c19798ac2dcbf3baaeb10 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Tue, 26 Mar 2013 15:19:43 -0700 Subject: [PATCH] hash-sets: simpler code. --- core/hash-sets/hash-sets.factor | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/core/hash-sets/hash-sets.factor b/core/hash-sets/hash-sets.factor index 07c663dcb6..9c8d4fbfe9 100644 --- a/core/hash-sets/hash-sets.factor +++ b/core/hash-sets/hash-sets.factor @@ -72,10 +72,7 @@ TUPLE: hash-set [ array>> length>> 1 fixnum-shift-fast ] bi fixnum> ; inline : each-member ( array quot: ( elt -- ) -- ) - [ - [ length ] keep - [ array-nth dup tombstone? [ drop ] ] curry - ] dip [ if ] curry compose each-integer ; inline + [ if ] curry [ dup tombstone? [ drop ] ] prepose each ; inline : grow-hash ( hash -- ) { hash-set } declare [ @@ -137,8 +134,9 @@ M: hash-set set-like INSTANCE: hash-set set -M: hash-set intersect - small/large sequence/tester filter >hash-set ; +! Overrides for performance + +M: hash-set intersect (intersect) >hash-set ; M: hash-set union over hash-set? [ @@ -148,8 +146,9 @@ M: hash-set union (union) >hash-set ] if ; -M: hash-set diff - sequence/tester [ not ] compose filter >hash-set ; +M: hash-set diff (diff) >hash-set ; + +! Default methods M: f fast-set drop 0 ;