util_subset_p (public)

 util_subset_p list1 list2

Defined in packages/acs-tcl/tcl/utilities-procs.tcl

Tests whether list1 is a subset of list2.

Parameters:
list1
list2
Returns:
1 if list1 is a subset of list2.
Author:
Peter Marklund

Partial Call Graph (max 5 caller/called nodes):
%3 test_util_subset_p util_subset_p (test acs-tcl) util_subset_p util_subset_p test_util_subset_p->util_subset_p

Testcases:
util_subset_p
Source code:
    if { [llength $list1] == 0 } {
        # The empty list is always a subset of any list
        return 1
    }

    #
    # We count every element of list1.
    #
    foreach e $list1 {
        incr l($e)
    }

    #
    # For every element in list2 that is in list1, we uncount. We exit
    # as soon as all of the elements in list1 are accounted for.
    #
    foreach e $list2 {
        if {[info exists l($e)] && [incr l($e) -1] <= 0} {
            unset l($e)
            if {[array size l] == 0} {
                break
            }
        }
    }

    #
    # Now we just make sure that no counter is left that is positive.
    #
    foreach {k v} [array get l] {
        if {$v > 0} {
            return 0
        }
    }

    return 1
XQL Not present:
PostgreSQL, Oracle
Generic XQL file:
packages/acs-tcl/tcl/utilities-procs.xql

[ hide source ] | [ make this the default ]
Show another procedure: