factor/library/collections/sequence-eq.factor

36 lines
868 B
Factor
Raw Normal View History

2005-07-16 22:16:18 -04:00
! Copyright (C) 2005 Slava Pestov.
2005-12-31 20:51:58 -05:00
! See http://factorcode.org/license.txt for BSD license.
2005-07-16 22:16:18 -04:00
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 -- ? )
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-12-10 01:02:13 -05:00
] if ; inline
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 ;