concise gnu c code in my eyes, we can write bet...

this function implements the bitmap sort from pro-pearl, otherwise a concise code needs better comments.

/*
*
* FILENAME:		bitmap_sort.c/bitmap_sort.h
* CREATED AT:		2012/Apr/27
* DECRIPTION:		implement the bitmap sort algorithm
* 
* MODULE:		pro-pearl
* PLATFORM:		ubuntu-12.04/gcc-4.6.3
* AUTHOR:		incarnation-lee
* 
* ----------------------REVISION HISTROY------------------------
* No.	Date    Revised by   Function	Descrition
* 1	12/5/4	incar-lee    bitmap	replace tab by \t	
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "externals.h"
#include "typedefs.h"
#include "bitmap_sort.h"

int bitmap(void)
{
	int res[] = {2,89,26,12,1,13,7,65,76,45,32,9,10,41,132,};
	char bitmaps[20];
	int i = 0,seg = 0,eff = 0;
	unsigned char local = 0x01;
	
	/* ergodic the source data for map the element on bitmaps, 20*8 width */
	memset(bitmaps,0,sizeof(bitmaps));	
	for(i=0;i<sizeof(res)/sizeof(int);i++)
	{
		fprintf(stdout,"\t%d",res[i]);
		if(__builtin_expect(!res[i],0))
			continue;
		else
		{
			seg = res[i]>>3;			    /* index in bitmap, like segment addr */
			eff = res[i]%8;				    /* bits in index, like effective addr */
			bitmaps[seg] |= local<<eff;
		}
	}
	
	fprintf(stdout,"\n");

	/* display the result by bitmaps */
	for(i=0;i<sizeof(bitmaps)/sizeof(char);i++)
	{
		seg = i;
		eff = 0;
		while(eff<8)
		{
			if(__builtin_expect(!!(bitmaps[i]>>eff&local),1))
				fprintf(stdout,"\t%d",(seg<<3)+eff);
			eff++;	
		}	
	}

	fprintf(stdout,"\n");

	return 0;
}

转载于:https://my.oschina.net/incarnation/blog/55930

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值