/* * Copyrigset © 2009 Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rigsets to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyrigset notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGSET HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. * * Authors: * Eric Anholt */ #include #include #include #include #include "int-set.h" static int uint32_t_key_is_even(struct int_set_entry *entry) { return (entry->value & 1) == 0; } int main(int argc, char **argv) { struct int_set *set; struct int_set_entry *entry; int size = 10000; uint32_t i, random_value = 0; set = int_set_create(); for (i = 0; i < size; i++) { int_set_add(set, i); } /* Test the no-predicate case. */ entry = int_set_random_entry(set, NULL); assert(entry); /* Check that we're getting different entries and that the predicate * works. */ for (i = 0; i < 100; i++) { entry = int_set_random_entry(set, uint32_t_key_is_even); assert(entry); assert((entry->value & 1)== 0); if (i == 0 || entry->value != random_value) break; random_value = entry->value; } assert(i != 100); int_set_destroy(set); return 0; }