1
22
2010
0

简单测试hash

 

#include <stdio.h>
#include <stdlib.h>
#include <search.h>  
#include <string.h>

#define NUM_EMPL 100000

int 
main(int argc, char * argv[])
{
    int i;
    struct timeval tv;
    struct timeval tv_e;
    
    if( (argc > 1) && (strcmp(argv[1], "hash") == 0) )
    {
        ENTRY   item;  
        ENTRY   *found_item;

        hcreate(NUM_EMPL);

        for( i = 0; i < NUM_EMPL; i++ )
        {
            item.key = (char *)malloc(16);
            item.data = (char *)malloc(16);
        
            sprintf(item.key, "%d", i);
            sprintf(item.data, "%d", i);

            hsearch(item, ENTER);
        }
    
        gettimeofday(&tv, NULL);

        item.key = "50000";

        if((found_item = hsearch(item, FIND)) != NULL)
        {
            printf( "found itaa!\n" );
        }
        else
        {
            printf( "no such data!\n" );
        }

        gettimeofday(&tv_e, NULL);
        printf("hash (%ld)us \n", (1000000*(tv_e.tv_sec - tv.tv_sec) + tv_e.tv_usec - tv.tv_usec));

    }
    else
    {
        int data_array[NUM_EMPL];
        int find_key = 50000;
    
        for(i = 0; i < NUM_EMPL; i++)
        {
            data_array[i] = i;
        }

        gettimeofday(&tv, NULL);

        for(i = 0; i < NUM_EMPL; i++)
        {
            if( data_array[i] == find_key )
            {
                printf( "found it!\n" );
                break;
            }
        }

        gettimeofday(&tv_e, NULL);
        printf("(%ld)us \n", (1000000*(tv_e.tv_sec - tv.tv_sec) + tv_e.tv_usec - tv.tv_usec));
            
    }

    
    
    return 0;
}

 

 

Category: linux | Tags:
1
20
2010
1

Maemo 5 Software Architecture

 

Category: linux | Tags:
11
6
2009
0

automake的一些问題

1.configure.in:173: warning: macro `AM_GLIB_GNU_GETTEXT' not found in library
   configure.in:510: warning: macro `AM_GCONF_SOURCE_2' not found in library

   解决:安装glib-dev和gconf-dev

Category: linux | Tags:
10
20
2009
0

ssh自动登录脚本 v0.1

#!/usr/bin/expect
set timeout 1 #设置超时阈值
set password 123456 #ssh登录密码
set ip1 "llj@10.1.4." #固定ip地址前端
spawn ssh $ip1[lindex $argv 0] #此处将命令参数进行组合,其中argv 0是第0个参数
expect "*password:" #期望一个密码
send "$password\r " #向进程发送字符串
interact


脚本完成自动登录ssh的功能

Category: linux | Tags:
9
20
2009
0

grub error 17

 ubuntu8.10在我的thinkpad sl400上经常关机异常,必须等待很久才能关掉。实在无法忍受这个漫长的等待就直接按Power键了。结果再次启动机器,到grub的时候就出现了error 17的问题。google了一下,发现解决的办法很简单,放入ubuntu 的CD Live,然后到终端,find grub stage1,结果我的机器上又出现不能找到文件系统的错误,error 15,郁闷。。。。。。。。没办法,fsck.ext3一下再说吧,完成,重启,一切恢复正常。所以,这个问题可能是根文件系统没有umount clearly导致的。

Category: linux | Tags:

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com