add .gitignore

This commit is contained in:
nonstriater
2014-05-10 19:50:03 +08:00
parent 39447dddd1
commit 06540b0631
38 changed files with 513 additions and 390 deletions
+11
View File
@@ -0,0 +1,11 @@
#include "stdio.h"
int main(){
int a = 257;
unsigned char *result = (unsigned char *)&a;
printf("%d.%d.%d.%d\n", result[0],result[1],result[2],result[3] );
}
+53
View File
@@ -0,0 +1,53 @@
#include "stdio.h"
int isSquare(unsigned integer){
if (integer==1 || integer==0)
{
return integer;
}
int divider=2,result=integer/divider;
while(result>divider){
divider++;
result = integer/divider;
}
if (result!=divider)
{
return -1;
}
return result;
}
int main(int argc, char const *argv[])
{
// 243,1849(43),289(17), 64(8)
int a[] = {1849,144,243,289,64,1194877489};
for (int i = 0; i < sizeof(a)/sizeof(int); ++i)
{
int ret = isSquare(a[i]);
if (ret==-1)
{
printf("%d 不是某个数的平方\n",a[i]);
}else{
printf("%d 是 %d 的平方\n", a[i], ret);
}
}
return 0;
}
Binary file not shown.
@@ -1,20 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.a.out</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
@@ -0,0 +1,135 @@
#include "stdio.h" // fwrite
#include "unistd.h" // write
#include "stdlib.h" // itoa
#include "string.h"
#define test_file_path2 "./ip2.txt"
#define test_file_path "./ip.txt"
#define ip_count 100000000 //随机1亿个IP
#define tmp_file_count 32
#define mem_count 128*1024*1028 //128MB个IP空间
int hash(unsigned i){
return i>>27;
}
int main(){
// 模拟创建一个文件,产生测试用的IP
// FILE *fd;
// fd = fopen(tmp_file_path,"a+");
// for (int i = 0; i < ip_count;++i)
// {
// //char c[] = "this is sentence!";
// unsigned random_ip = (unsigned)rand();
// char tmp[50];
// sprintf(tmp,"%d",random_ip);
// //printf("random ip = %s\n",tmp);
// fwrite(tmp,strlen(tmp),1,fd);
// fputc('\n',fd);//加入换行符号
// }
//创建临时文件
FILE *fd[tmp_file_count];
for (int i = 0; i < tmp_file_count; ++i)
{
char file_path[128];
//s[0]=(char)(i+48);
//char *file_path = strcat("./ipslice/ipslice",s) ; // 这样写出现 bus error!!!
sprintf(file_path,"./ipslice/ipslice%d",i);
fd[i] = fopen(file_path ,"a+" );
if ( !fd[i])
{
printf("file %d open fail!! \n" ,i);
}
}
//开始读测试数据IP,按IP,映射到32个文件中
FILE *testfd = fopen(test_file_path2,"r");
if (!testfd)
{
printf("file open fail !!\n");
exit(-1);
}
unsigned tmp_data;
while( getline() ){ //能读到数据 // fread(&tmp_data,sizeof(unsigned),1,testfd) , C语言中没有getline() 这样的函数
printf("%d\n",(unsigned)tmp_data );
int key = hash((unsigned)tmp_data);// key值即为对应文件fd
int size = fwrite(&tmp_data,sizeof(unsigned),1,fd[key]);
printf("写入数据size=%d ,key=%d\n",size, key );
//跳过换行符
fseek(testfd,1,SEEK_CUR);
}
// 依次读入每个文件并统计, hash_map 统计每个区间段的最大IP
int hash_map[mem_count];
int max_ip;
int max_times;
for (int i = 0; i < tmp_file_count; ++i)
{
// hash统计
while(){}
//hash 表里找出最大的,变量一遍
for (int i = 0; i < mem_count; ++i)
{
/* code */
}
}
// 释放
for (int i = 0; i < tmp_file_count; ++i)
{
fclose(fd[i]);
}
return 0;
}
/**
关于warning
implicit declaration of function 'itoa' is invalid in C99
itoa() 函数并不是一个 standard functions ANSI C standard
inet_ntop() // 整数转换成 .分 ip地址 字符串
inet_nton() //
inet_aton() //
struct in_addr
*/