amittai的B+tree1.12版本的dot输出补丁
2013-10-17 17:12
204 查看
--- bpt.c 2013-10-15 07:54:12 +0800 +++ bpt1.c 2013-10-17 17:04:37 +0800 @@ -48,6 +48,7 @@ // #define WINDOWS #include <stdio.h> #include <stdlib.h> +#include <time.h> #include <stdbool.h> #ifdef WINDOWS #define bool char @@ -288,6 +289,7 @@ printf("\tx -- Destroy the whole tree. Start again with an empty tree of the same order.\n"); printf("\tt -- Print the B+ tree.\n"); printf("\tl -- Print the keys of the leaves (bottom row of the tree).\n"); + printf("\tD -- Print the B+ tree to .dot file.\n"); printf("\tv -- Toggle output of pointer addresses (\"verbose\") in tree and leaves.\n"); printf("\tq -- Quit. (Or use Ctl-D.)\n"); printf("\t? -- Print this help message.\n"); @@ -446,6 +448,55 @@ printf("\n"); } +void print_tree_file( node * root ) +{ + FILE *fp; + time_t tim; + struct tm *at; + char filename[64]; + + node * n = NULL; + int i = 0; + + time(&tim); + at = localtime(&tim); + strftime(filename, 63, "%Y%m%d%H%M%S.dot", at); + fp = fopen(filename, "w"); + if( fp == NULL ) { + printf("open %s error\n", filename); + return; + } + fprintf(fp, "digraph {\n"); + fprintf(fp, "graph[ordering=\"out\"];\n"); + fprintf(fp, "node[fontcolor=\"#990000\",shape=plaintext];\n"); + fprintf(fp, "edge[arrowsize=0.6,fontsize=6];\n"); + if( root == NULL ) { + fprintf(fp, "null[shape=box]\n"); + return; + } + queue = NULL; + enqueue(root); + while ( queue != NULL ) { + n = dequeue(); + fprintf(fp, "n%p[label=\"", n); + for (i = 0; i < n->num_keys; i++) { + fprintf(fp, " %d ", n->keys[i]); + } + fprintf(fp, "\",shape=box];\n"); + if (!n->is_leaf) { + for (i = 0; i <= n->num_keys; i++) { + fprintf(fp, " n%p -> n%p;\n", n, n->pointers[i]); + enqueue(n->pointers[i]); + } + } + else { + if(n->pointers[order - 1]) + fprintf(fp, " n%p -> n%p[constraint=false];\n", n, n->pointers[order - 1]); + } + } + fprintf(fp, "}\n"); + fclose(fp); +} /* Finds the record under a given key and prints an * appropriate message to stdout. @@ -1501,6 +1552,9 @@ case 't': print_tree(root); break; + case 'D': + print_tree_file(root); + break; case 'v': verbose_output = !verbose_output; break;
相关文章推荐
- [转]ASP.NET 缓存(十一)--缓存用户控件输出的多个版本
- oracle 10g 各版本及补丁下载地址
- DotNetNuke 5 C#版本解读之1--架构介绍
- NSLog使用,在release版本禁止输出NSLog内容
- git日志输出格式及两个版本之间差异列表
- 如何查看SQL Server 补丁的版本?
- DotNetNuke 5 C#版本解读之1--架构介绍
- 安装非英语版本的 Microsoft Visual Studio 2008 Service Pack 1 后,智能提示变为英文的临时补丁发布
- 明明白白WAS&amp;IBM JDK的版本以及它们各安装了哪些补丁!
- as通过gradle实现多渠道打包+使用配置文件进行版本管理+指定apk输出路径和apk文件名
- XE版本 运行cmd命令,并取得输出字符
- Oracle10G各版本下载以及补丁地址
- 查看sqlserver版本及其补丁
- 缓存用户控件输出的多个版本
- Oracle10G各版本下载以及补丁地址
- 使用AXIS2开发Webservice成功输出版本信息——小白入门
- 不重启IIS修改dotnet framework版本
- bugly热更新,提交补丁时提示未匹配到可应用补丁包的APP版本,请确认补丁包的基线版本是否配置正确