static int map_test(mapnode_t *node) { /* got this routine by Julienne Walker from * http://eternallyconfuzzled.com/tuts/datastructures/jsw_tut_rbtree.aspx */ mapnode_t *left, *right; if (node == NIL) return 1; left = node->left; right = node->right; if (IS_RED(node) && (IS_RED(right) || IS_RED(right))) { s_log_note("Red violation on node with key %p\n", node->key); return 0; } int lh = map_test(left); int rh = map_test(right); if (left != NIL && left->key > node->key) { s_log_note("Left node (key: %p) of parent node (key: %p) is incorrectly ordered\n", left->key, node->key); return 0; } if (right != NIL && right->key < node->key) { s_log_note("Right node (key: %p) of parent node (key: %p) is incorrectly ordered\n", right->key, node->key); return 0; } if (lh && rh) return IS_RED(node) ? lh : lh + 1; else return 0; }
static int __init test_treemap_init(void) { printk(KERN_INFO "test_treemap_init begin\n"); if (!initialize()) { printk(KERN_ERR "initialize() failed.\n"); goto error; } /* Treemap test for debug. */ if (map_test()) { printk(KERN_ERR "map_test() failed.\n"); goto error; } if (map_cursor_test()) { printk(KERN_ERR "map_cursor_test() failed.\n"); goto error; } if (multimap_test()) { printk(KERN_ERR "multimap_test() failed.\n"); goto error; } if (multimap_cursor_test()) { printk(KERN_ERR "multimap_cursor_test() failed.\n"); goto error; } finalize(); printk(KERN_INFO "test_treemap_init end\n"); error: return -1; }
int main(int ac, char **av) { if (ac > 1) av_manage(ac - 1, av + 1); else map_test(0); return (0); }
void test13 ( ) /******************************************************************************/ /* Purpose: TEST13 tests MAP_TEST. Licensing: This code is distributed under the GNU LGPL license. Modified: 22 January 2013 Author: John Burkardt */ { printf ( "\n" ); printf ( "TEST13\n" ); printf ( " MAP_TEST tests the map routines.\n" ); map_test ( "Q4" ); map_test ( "Q8" ); map_test ( "Q9" ); map_test ( "Q12" ); map_test ( "Q16" ); map_test ( "QL" ); map_test ( "T3" ); map_test ( "T6" ); map_test ( "T10" ); return; }
void av_manage(int ac, char **maps) { int i; int fd; i = -1; while (++i < ac) { fd = open(maps[i], O_RDONLY); map_test(fd); close(fd); } }
int _tmain(int argc, _TCHAR* argv[]) { //vecAssignTest(); map_test(); vector_member(); set_test(); hash_set_test(); iterator_test2(); example_algorithm(); example_iterator(); list_test(); autoptr_test(); return 0; }
void part_two_describe() { cout<<"******************************************"<<endl; cout<<"* 第二章 C++ STL泛型编程 *"<<endl; cout<<"******************************************"<<endl; cout<<"*(1) 一个简单的测试案例 *"<<endl; cout<<"*(2) vector向量容器 *"<<endl; cout<<"*(3) string基本字符系列容器 *"<<endl; cout<<"*(4) set集合容器 *"<<endl; cout<<"*(5) mutiset多种集合容器 *"<<endl; cout<<"*(6) map映照容器 *"<<endl; cout<<"*(7) mutimap多重映照容器 *"<<endl; cout<<"*(8) deque双端队列容器 *"<<endl; cout<<"*(9) list双向链表容器 *"<<endl; cout<<"*(10)bitset位集合容器 *"<<endl; cout<<"*(11)stack堆栈容器 *"<<endl; cout<<"*(12)queue队列容器 *"<<endl; cout<<"*(13)priority_queue优先队列容器 *"<<endl; cout<<"******************************************"<<endl; cout<<"请输入对应的编号进入相应的题目(返回上级输入0):"<<endl; int num; cin>>num; while(num!=0&&num!=1&&num!=2&&num!=3&&num!=4&&num!=5&&num!=6&&num!=7&&num!=8&&num!=9&&num!=10&&num!=11&&num!=12&&num!=13){ cout<<"编号不存在"<<endl; cout<<"请输入对应的编号进入相应的题目(返回上级输入0):"<<endl; cin>>num; } switch(num){ case 0:total_describe();break; case 1:test();break; case 2:vector_test();break; case 3:string_test();break; case 4:set_test();break; case 5:multiset_test();break; case 6:map_test();break; case 7:multimap_test();break; case 8:deque_test();break; case 9:list_test();break; case 10:bitset_test();break; case 11:stack_test();break; case 12:queue_test();break; case 13:priority_queue_test();break; } }
int run_main (int, ACE_TCHAR *[]) { ACE_START_TEST (ACE_TEXT ("Lazy_Map_Manager_Test")); ACE_LOG_MSG->clr_flags (ACE_Log_Msg::VERBOSE_LITE); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nMap Manager...\n\n"))); map_test (); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nActive Map Manager...\n\n"))); active_map_test (); ACE_LOG_MSG->set_flags (ACE_Log_Msg::VERBOSE_LITE); ACE_END_TEST; return 0; }
void map_insert(map_t *map, mapkey_t key, void *p) { allocator_t *alloc = map->allocator; mapnode_t *parent = map->root; mapnode_t **slot = &map->root; mapnode_t *insert; while (parent != NIL) { int comparison = map->ops.compare_key(key, parent->key); if (comparison == 0) { map->ops.destroy_value(parent->p, alloc); parent->p = map->ops.copy_value(p, alloc); return; } else if (comparison < 0) { if (parent->left != NIL) { parent = parent->left; continue; } else { slot = &parent->left; break; } } else { if (parent->right != NIL) { parent = parent->right; continue; } else { slot = &parent->right; break; } } } map->size += 1; insert = (mapnode_t *)com_malloc(map->allocator, sizeof(mapnode_t)); insert->left = insert->right = NIL; insert->key = map->ops.copy_key(key, alloc); insert->p = map->ops.copy_value(p, alloc); insert->color = RED; insert->parent = parent; *slot = insert; while (IS_RED(insert->parent) && node_grandparent(insert) != NIL) { mapnode_t *uncle = node_sibling(insert->parent); if (IS_RED(uncle)) { insert->parent->color = BLACK; uncle->color = BLACK; uncle->parent->color = RED; insert = uncle->parent; } else { int insleft = IS_LEFT(insert); int parleft = IS_LEFT(insert->parent); if (!insleft && parleft) { insert = insert->parent; node_rotate_left(map, insert); } else if (insleft && !parleft) { insert = insert->parent; node_rotate_right(map, insert); } insert->parent->parent->color = RED; insert->parent->color = BLACK; if (parleft) node_rotate_right(map, insert->parent->parent); else node_rotate_left(map, insert->parent->parent); } } map->root->color = BLACK; #if !defined(NDEBUG) map_test(map->root); #endif }
static void mapnode_remove(map_t *map, mapnode_t *node) { allocator_t *alloc = map->allocator; mapnode_t *destroyed, *y, *z; if (node->left == NIL) { destroyed = node; y = node->right; } else if (node->right == NIL) { destroyed = node; y = node->left; } else { destroyed = node->left; while (destroyed->right != NIL) destroyed = destroyed->right; y = destroyed->left; node->key = destroyed->key; node->p = destroyed->p; } z = destroyed->parent; if (y != NIL) y->parent = z; if (z == NIL) { map->root = y; goto finish_removal; } if (destroyed == z->left) { z->left = y; } else { z->right = y; } if (IS_BLACK(destroyed)) { while (y != map->root && IS_BLACK(y)) { mapnode_t *sibling; int dir = !(y == z->left); sibling = OPP_NODE(z, dir); if (IS_RED(sibling)) { sibling->color = BLACK; z->color = RED; g_rotations[dir](map, z); sibling = OPP_NODE(z, dir); } if (IS_BLACK(sibling->left) && IS_BLACK(sibling->right)) { sibling->color = RED; y = z; z = z->parent; } else { if (IS_BLACK(OPP_NODE(sibling, dir))) { DIR_NODE(sibling, dir)->color = BLACK; sibling->color = RED; g_rotations[!dir](map, sibling); sibling = OPP_NODE(z, dir); } sibling->color = z->color; z->color = BLACK; OPP_NODE(sibling, dir)->color = BLACK; g_rotations[dir](map, z); y = map->root; } } y->color = BLACK; } finish_removal: com_free(alloc, destroyed); map->size -= 1; #if !defined(NDEBUG) map_test(map->root); #endif }
int main() { map_test(); return 0; }
void test_metric() { hop_test(); map_test(); }