int main (int argc, char *argv[]) { gl_oset_t set1, set2; /* Allow the user to provide a non-default random seed on the command line. */ if (argc > 1) srand (atoi (argv[1])); { size_t initial_size = RANDOM (20); size_t i; unsigned int repeat; /* Create set1. */ set1 = gl_oset_create_empty (GL_ARRAY_OSET, (gl_setelement_compar_fn) strcmp, NULL); /* Create set2. */ set2 = gl_oset_create_empty (GL_AVLTREE_OSET, (gl_setelement_compar_fn) strcmp, NULL); check_all (set1, set2); /* Initialize them. */ for (i = 0; i < initial_size; i++) { const char *obj = RANDOM_OBJECT (); ASSERT (gl_oset_add (set1, obj) == gl_oset_add (set2, obj)); check_all (set1, set2); } for (repeat = 0; repeat < 100000; repeat++) { unsigned int operation = RANDOM (3); switch (operation) { case 0: { const char *obj = RANDOM_OBJECT (); ASSERT (gl_oset_search (set1, obj) == gl_oset_search (set2, obj)); } break; case 1: { const char *obj = RANDOM_OBJECT (); ASSERT (gl_oset_add (set1, obj) == gl_oset_add (set2, obj)); } break; case 2: { const char *obj = RANDOM_OBJECT (); ASSERT (gl_oset_remove (set1, obj) == gl_oset_remove (set2, obj)); } break; } check_all (set1, set2); } gl_oset_free (set1); gl_oset_free (set2); } return 0; }
void make_diversion (int divnum) { m4_diversion *diversion = NULL; if (current_diversion == divnum) return; if (output_diversion) { if (!output_diversion->size && !output_diversion->u.file) { assert (!output_diversion->used); if (!gl_oset_remove (diversion_table, output_diversion)) assert (false); output_diversion->u.next = free_list; free_list = output_diversion; } else if (output_diversion->size) output_diversion->used = output_diversion->size - output_unused; else if (output_diversion->used) { FILE *file = output_diversion->u.file; output_diversion->u.file = NULL; if (m4_tmpclose (file, output_diversion->divnum) != 0) m4_error (0, errno, _("cannot close temporary file for diversion")); } output_diversion = NULL; output_file = NULL; output_cursor = NULL; output_unused = 0; } current_diversion = divnum; if (divnum < 0) return; if (divnum == 0) diversion = &div0; else { const void *elt; if (gl_oset_search_atleast (diversion_table, threshold_diversion_CB, &divnum, &elt)) { m4_diversion *temp = (m4_diversion *) elt; if (temp->divnum == divnum) diversion = temp; } } if (diversion == NULL) { /* First time visiting this diversion. */ if (free_list) { diversion = free_list; free_list = diversion->u.next; } else { diversion = (m4_diversion *) obstack_alloc (&diversion_storage, sizeof *diversion); diversion->size = 0; diversion->used = 0; } diversion->u.file = NULL; diversion->divnum = divnum; gl_oset_add (diversion_table, diversion); } output_diversion = diversion; if (output_diversion->size) { output_cursor = output_diversion->u.buffer + output_diversion->used; output_unused = output_diversion->size - output_diversion->used; } else { if (!output_diversion->u.file && output_diversion->used) output_diversion->u.file = m4_tmpopen (output_diversion->divnum, false); output_file = output_diversion->u.file; } output_current_line = -1; }