用败者树实现求共同的元素(在归并程序上加上筛子)
来源:互联网 发布:js如何产生随机数 编辑:程序博客网 时间:2024/06/11 15:54
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 999999999
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 999999999
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 999999999
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 999999999
9 10 11 12 13 14 15 16 17 18
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#include <stdio.h>
#include <stdlib.h>
typedef struct wrap_data
{
int offset;
int path;
int *data;
}wrap_data;
int choosevec(int path)
{
if(path<=4)
{
return 4;
}
else if (path<=8)
{
return 8;
}
else if(path<=16)
{
return 16;
}
else
{
return 32;
}
}
wrap_data **vec;
int vecsize;
wrap_data * up ( int num )
{
int i,j,k;
wrap_data *first,*second;
i=num;
second=vec[i];
while(i)
{
j=i/2;
first=vec[j];
if(!first)
{
vec[j]=second;
if (!j)
{
return second;
}
else
{
return NULL;
}
}
if ( first->path==second->path)
{
i=j;
}
else if ( *( second->data + second->offset )> *( first->data + first->offset ))
{
vec[j]=second;
second=first;
i=j;
}
else
{
i=j;
}
}
return second;
}
int main()
{
#define PATH 4
#define LENGTH 20
#define MAX_BIG 999999999
wrap_data *result;
int i=0,j=0,k=0;
wrap_data a[PATH]={0};
int last_docid=MAX_BIG;
int count_docid=0;
vecsize=2* choosevec(PATH);
vec=(wrap_data **)calloc( vecsize ,sizeof (wrap_data*));
for(i=0;i<PATH;i++)
{
a[i].data=(int*) calloc (LENGTH , sizeof (int ));
a[i].offset=0;
a[i].path=i;
for(j=0;j<LENGTH;j++)
{
*(a[i].data+j)=(i*i+j);
}
*(a[i].data+LENGTH-1)=MAX_BIG;
}
for(i=0;i<PATH;i++)
{
for(j=0;j<LENGTH;j++)
{
printf("%d ", *(a[i].data+j));
}
printf("\n");
}
k=vecsize/2;
for(i=0;i<PATH;i++)
{
vec[k+i]=&a[i];
}
for(i=0;i<PATH;i++)
{
result=up(i+k);
if(!result)
{
}
else
{
break;
}
}
while(result)
{
// printf(" %d ", *(result->data+result->offset));
if ( *(result->data+result->offset) == last_docid )
{
count_docid++;
if (count_docid == PATH)
{
printf(" %d ", *(result->data+result->offset));
last_docid=MAX_BIG;
}
}
else
{
last_docid=*(result->data+result->offset) ;
count_docid=1;
}
//add a sed for the result by chenbing 2011.11.14
if (result->offset>=LENGTH)
{
break;
}
result->offset++;
result=up(result->path+k);
}
printf("\n");
}
- 用败者树实现求共同的元素(在归并程序上加上筛子)
- 用败者树做的多路归并程序
- k路归并 - 败者树实现
- 外排之多路归并的败者树
- 求质数的筛子
- 归并排序-败者树
- 败者树的实现(c++)
- 败者树的Java实现
- 败者树的java实现
- 外排序的C++实现(归并时利用败者树)
- 败者树实现多路平衡归并外部排序算法
- 败者树实现多路平衡归并外部排序算法
- python实现k路归并排序,败者树
- 多路归并—败者树—简单实现
- 实现“挨拉托色尼的筛子”
- 归并算法、赢者树、败者树
- 二路归并的一个版本(寻找共同的元素)
- 多路归并使用败者树的性能分析
- Charles使用
- 2012校园招聘的一道笔试题目
- LED知识(三)
- util HashMap
- 工作相关
- 用败者树实现求共同的元素(在归并程序上加上筛子)
- linux中实现getch函数
- consistent gets减少,cost增加?
- Android系统默认值的设置
- oracle 参数详解
- 要创业,学校教不会你这10招
- Android深入浅出系列之Bluetooth—蓝牙操作(二)
- 关闭笔记本电脑显示屏的小软件
- linux shell 中"2>&1"含义