X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=isl_scan.c;h=a7d2b9f4edf1843959be13e4bfb28ee83217ee6a;hb=989f832a4354ae34f538b032c355dc7191b10e27;hp=c8eba377c8a2b89486f4acfb8c16b6e784fc00b0;hpb=d32aba8b9178a16b1f65c392cefbdc8312504890;p=platform%2Fupstream%2Fisl.git diff --git a/isl_scan.c b/isl_scan.c index c8eba37..a7d2b9f 100644 --- a/isl_scan.c +++ b/isl_scan.c @@ -1,17 +1,19 @@ /* * Copyright 2008-2009 Katholieke Universiteit Leuven * - * Use of this software is governed by the GNU LGPLv2.1 license + * Use of this software is governed by the MIT license * * Written by Sven Verdoolaege, K.U.Leuven, Departement * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium */ +#include +#include #include "isl_basis_reduction.h" #include "isl_scan.h" -#include "isl_seq.h" +#include #include "isl_tab.h" -#include +#include struct isl_counter { struct isl_scan_callback callback; @@ -78,7 +80,7 @@ static int scan_0D(struct isl_basic_set *bset, return callback->add(callback, sample); } -/* Look for all integer points in "bset", which is assumed to be unbounded, +/* Look for all integer points in "bset", which is assumed to be bounded, * and call callback->add on each of them. * * We first compute a reduced basis for the set and then scan @@ -123,7 +125,7 @@ int isl_basic_set_scan(struct isl_basic_set *bset, if (!min || !max || !snap) goto error; - tab = isl_tab_from_basic_set(bset); + tab = isl_tab_from_basic_set(bset, 0); if (!tab) goto error; if (isl_tab_extend_cons(tab, dim + 1) < 0) @@ -242,6 +244,33 @@ error: return -1; } +int isl_basic_set_count_upto(__isl_keep isl_basic_set *bset, + isl_int max, isl_int *count) +{ + struct isl_counter cnt = { { &increment_counter } }; + + if (!bset) + return -1; + + isl_int_init(cnt.count); + isl_int_init(cnt.max); + + isl_int_set_si(cnt.count, 0); + isl_int_set(cnt.max, max); + if (isl_basic_set_scan(isl_basic_set_copy(bset), &cnt.callback) < 0 && + isl_int_lt(cnt.count, cnt.max)) + goto error; + + isl_int_set(*count, cnt.count); + isl_int_clear(cnt.max); + isl_int_clear(cnt.count); + + return 0; +error: + isl_int_clear(cnt.count); + return -1; +} + int isl_set_count_upto(__isl_keep isl_set *set, isl_int max, isl_int *count) { struct isl_counter cnt = { { &increment_counter } }; @@ -274,3 +303,21 @@ int isl_set_count(__isl_keep isl_set *set, isl_int *count) return -1; return isl_set_count_upto(set, set->ctx->zero, count); } + +/* Count the total number of elements in "set" (in an inefficient way) and + * return the result. + */ +__isl_give isl_val *isl_set_count_val(__isl_keep isl_set *set) +{ + isl_val *v; + + if (!set) + return NULL; + v = isl_val_zero(isl_set_get_ctx(set)); + v = isl_val_cow(v); + if (!v) + return NULL; + if (isl_set_count(set, &v->n) < 0) + v = isl_val_free(v); + return v; +}