Mercurial > libavutil.hg
comparison tree.c @ 701:ae6e96434bec libavutil
Replace random() usage in test programs by av_lfg_*().
author | diego |
---|---|
date | Fri, 20 Mar 2009 11:48:27 +0000 |
parents | 8c48a1b999a3 |
children | 3f3e69baaaf8 |
comparison
equal
deleted
inserted
replaced
700:e110508543ac | 701:ae6e96434bec |
---|---|
142 if(v<=0) av_tree_enumerate(t->child[1], opaque, f); | 142 if(v<=0) av_tree_enumerate(t->child[1], opaque, f); |
143 } | 143 } |
144 #endif | 144 #endif |
145 | 145 |
146 #ifdef TEST | 146 #ifdef TEST |
147 #undef random | 147 |
148 #include "lfg.h" | |
149 | |
148 static int check(AVTreeNode *t){ | 150 static int check(AVTreeNode *t){ |
149 if(t){ | 151 if(t){ |
150 int left= check(t->child[0]); | 152 int left= check(t->child[0]); |
151 int right= check(t->child[1]); | 153 int right= check(t->child[1]); |
152 | 154 |
177 } | 179 } |
178 | 180 |
179 int main(void){ | 181 int main(void){ |
180 int i,k; | 182 int i,k; |
181 AVTreeNode *root= NULL, *node=NULL; | 183 AVTreeNode *root= NULL, *node=NULL; |
184 AVLFG prn; | |
185 | |
186 av_lfg_init(&prn, 1); | |
182 | 187 |
183 for(i=0; i<10000; i++){ | 188 for(i=0; i<10000; i++){ |
184 int j= (random()%86294); | 189 int j = av_lfg_get(&prn) % 86294; |
185 if(check(root) > 999){ | 190 if(check(root) > 999){ |
186 av_log(NULL, AV_LOG_ERROR, "FATAL error %d\n", i); | 191 av_log(NULL, AV_LOG_ERROR, "FATAL error %d\n", i); |
187 print(root, 0); | 192 print(root, 0); |
188 return -1; | 193 return -1; |
189 } | 194 } |
190 av_log(NULL, AV_LOG_ERROR, "inserting %4d\n", j); | 195 av_log(NULL, AV_LOG_ERROR, "inserting %4d\n", j); |
191 if(!node) | 196 if(!node) |
192 node= av_mallocz(av_tree_node_size); | 197 node= av_mallocz(av_tree_node_size); |
193 av_tree_insert(&root, (void*)(j+1), cmp, &node); | 198 av_tree_insert(&root, (void*)(j+1), cmp, &node); |
194 | 199 |
195 j= (random()%86294); | 200 j = av_lfg_get(&prn) % 86294; |
196 { | 201 { |
197 AVTreeNode *node2=NULL; | 202 AVTreeNode *node2=NULL; |
198 av_log(NULL, AV_LOG_ERROR, "removing %4d\n", j); | 203 av_log(NULL, AV_LOG_ERROR, "removing %4d\n", j); |
199 av_tree_insert(&root, (void*)(j+1), cmp, &node2); | 204 av_tree_insert(&root, (void*)(j+1), cmp, &node2); |
200 k= av_tree_find(root, (void*)(j+1), cmp, NULL); | 205 k= av_tree_find(root, (void*)(j+1), cmp, NULL); |