factor/library/collections/sequence-eq.factor

38 lines
978 B
Factor
Raw Normal View History

2005-07-16 22:16:18 -04:00
! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: sequences
USING: arrays kernel lists math sequences-internals strings
vectors ;
2005-07-16 22:16:18 -04:00
! Note that the sequence union does not include lists, or user
! defined tuples that respond to the sequence protocol.
UNION: sequence array string sbuf vector ;
: sequence= ( seq seq -- ? )
#! Check if two sequences have the same length and elements,
#! but not necessarily the same class.
2dup [ length ] 2apply = [
dup length [ >r 2dup r> 2nth-unsafe = ] all? 2nip
2005-07-16 22:16:18 -04:00
] [
2005-08-25 15:27:38 -04:00
2drop f
2005-09-24 15:21:17 -04:00
] if ; flushable
2005-07-16 22:16:18 -04:00
M: sequence = ( obj seq -- ? )
2dup eq? [
2drop t
] [
2005-09-24 15:21:17 -04:00
over type over type eq? [ sequence= ] [ 2drop f ] if
] if ;
M: sequence hashcode ( seq -- n )
#! Poor
length ;
M: string = ( obj str -- ? )
over string? [
over hashcode over hashcode number=
2005-09-24 15:21:17 -04:00
[ sequence= ] [ 2drop f ] if
] [
2drop f
2005-09-24 15:21:17 -04:00
] if ;