REBOL Document

Intersect - Function Summary


Summary:

Create a new value that is the intersection of the two arguments.

Usage:

intersect ser1 ser2

Arguments:

ser1 - first set (must be: series bitset)

ser2 - second set (must be: series bitset)

Refinements:

/case - Uses case-sensitive comparison.

/skip - Treat the series as records of fixed size

size - The size argument. (must be: integer)

Description:

Returns all elements within two blocks or series that exist in both.


    lunch: [ham cheese bread carrot]
    dinner: [ham salad carrot rice]
    probe intersect lunch dinner
    [ham carrot]


    probe intersect [1 3 2 4] [3 5 4 6]
    [3 4]


    string1: "CBAD"    ; A B C D scrambled
    string2: "EDCF"    ; C D E F scrambled
    probe intersect string1 string2
    "CD"


    items: [1 1 2 3 2 4 5 1 2]
    probe intersect items items  ; get unique set
    [1 2 3 4 5]


    str: "abcacbaabcca"
    probe intersect str str
    "abc"

To obtain a unique set (to remove duplicate values) you can use UNIQUE.

Note that performing this function over very large data sets can be CPU intensive.

Related:

difference - Return the difference of two data sets.
union - Creates a new set that is the union of the two arguments.


<Back | Index | Next>

Copyright 2004 REBOL Technologies