- 博客(26)
- 资源 (7)
- 收藏
- 关注
原创 Texture Synthesis
/*Reference:Texture synthesis by non-parametric sampling.pdfhttp://en.wikipedia.org/wiki/Texture_synthesisPotential applications: A successful texture synthesis algorithm's application is abroad
2013-09-10 17:14:49
770
转载 简单的echo服务器程序
#include #include #include #include #include #include #include #include#define SERVERIP "192.168.1.193"#define SERVERPORT 12345#define MAXBUFFER 256int main(int argc, char** argv){ i
2013-08-29 11:57:00
931
原创 linux异步IO
linux下主要有两套异步IO,一套是由glibc实现的(以下称之为glibc版本)、一套是由linux内核实现,并由libaio来封装调用接口(以下称之为linux版本)。比较从上面的流程可以看出,linux版本的异步IO实际上只是利用了CPU和IO设备可以异步工作的特性(IO请求提交的过程主要还是在调用者线程上同步完成的,请求提交后由于CPU与IO设备可以并行工作,所以调用流程
2013-08-28 17:42:18
536
原创 简单多线程
#include #include #include #define NUM 6void *thread_function(void *arg);int main(){ int res; pthread_t a_thread[NUM]; void *thread_result; int index; for (index = 0; ind
2013-08-10 23:26:41
434
原创 取消一个线程
#include #include #include void *thread_function(void *arg);int main(){ int res; pthread_t a_thread; void *thread_result; res = pthread_create(&a_thread, NULL, thread_function,
2013-08-10 23:14:24
438
原创 使用互斥量实现线程间同步
#include #include #include #include #include #define SIZE 1024char buffer[SIZE];void *thread_function(void *arg);pthread_mutex_t mutex;int main(){ int res; pthread_t a_thread;
2013-08-10 12:31:24
744
原创 使用信号量实现线程间同步
#include #include #include #include #include #define SIZE 1024void *thread_function(void *arg);char buffer[SIZE];sem_t sem;int main(){ int res; pthread_t a_thread; void *thre
2013-08-10 12:25:44
737
原创 轮询方式实现线程间共享变量
#include #include #include int flag = 1;void *thread_function(void *arg);int main(){ int res; pthread_t a_thread; void *thread_result; int count = 1; res = pthread_create
2013-08-10 11:51:47
536
转载 linux-多线程
From: http://blog.youkuaiyun.com/lanyan822/article/details/7586845线程的创建 使用pthread_create函数。 #include int pthread_create (pthread_t *__restrict __newthread,//新创建的线程ID
2013-08-09 11:36:53
423
转载 条件变量
http://blog.youkuaiyun.com/lanyan822/article/details/7586845条件变量用pthread_cond_t数据类型表示。条件变量本身由互斥量保护,所以在改变条件状态前必须锁住互斥量。条件变量初始化:第一种,赋值常量PTHREAD_COND_INITIALIZER;第二种,使用pthread_cond_init函数int
2013-08-09 11:27:30
426
原创 find the N max numbers from an array
//find the N max numbers from an array#include using namespace std;void swap(int &a, int &b){ int tmp = a; a = b; b = tmp;}int partition(int *data, int beg, int end){ int pos
2013-08-07 14:12:31
457
原创 count the number of 1 in a decimal integer
#include using namespace std;long count1sOfInteger(int num){ long res = 0; int factor = 1; long high, cur, low; while(num / factor) { low = num - (num/factor)*factor;
2013-08-07 12:00:49
592
原创 implement of power(double base, int expo), without using math library.
#include #include #include using namespace std;#define MIN 1e-6bool equal(double a, double b){ if(fabs(a-b) < MIN) return true; return false;}#if 0double myPower(double ba
2013-08-06 21:31:29
584
原创 compute the max sum of a continuours subset
// compute the max sum of a continuours subset#include #include using namespace std;int maxMultiply(int *data, int beg, int end){ int minRes, maxRes, res; minRes = maxRes = r
2013-08-06 15:15:17
659
原创 compute the max sum of a continuours subset
#include #include using namespace std;int partition(int *data, int beg, int end){ int mid = beg + (end-beg)/2; if(beg > end) return 0; else if(beg == end) return data
2013-08-06 12:20:51
515
原创 implementation of string class
#include #include using namespace std;class myString{public: //myString(); myString(const char *str = NULL); myString(const myString &other); myString& operator=(const myString
2013-08-06 10:51:50
567
原创 print the numbers less than the max n-bit integer
#include #include #include #include #include using namespace std;void print1ToNDigits(char *buf, int beg, int len){ if(beg == len-1) { cout << buf << endl; return;
2013-08-06 01:30:38
526
原创 String combination
#include #include #include #include #include using namespace std;#if 0void combination(const char *str, int m, vector &res){ if(*str == '\0' && m != 0) return; if(m == 0)
2013-08-05 17:39:05
544
原创 String permutation
#include #include #include using namespace std;void Permutation(char *str, char *beg){ if(*beg == '\0') cout << str <<endl; else { for(char *tmp = beg; *tmp != '\0'; tmp++) {
2013-08-05 14:05:57
680
原创 calculate the distance of two string
#include #include #include using namespace std;#define MIN(x, y, z) ((x < y) ? (x < z ? x : z) : (y < z ? y : z)) int calcStringDistance(const string &s1, int beg1, int end1, const string &s2,
2013-08-04 15:12:37
461
原创 implement of sqrt without using stdlib
/** binary search using */// sqrt.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include #include #include using namespace std;double mySqrt(d
2013-07-11 21:30:45
439
转载 二值图像连通域标记算法与代码
转自 http://www.verydemo.com/demo_c180_i27000.htmlReference paper: A Simple and Efficient Connected Components Labeling Algorithm 这里列举二值图像连通域标记算法包括直接扫描标记算法和二值图像连通域标记快速算法一、直接扫描标记算法把连续区域作同一个标记,常
2013-07-03 22:48:04
1393
原创 Radix Sort
// RadixSort.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include #include #include #include #include using namespace std;int rxSort(int *data,
2013-06-29 23:24:50
577
原创 Search the Nth element of Level M in a binary tree
// binTreeMN.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include #include using namespace std;struct Node{ int val; Node *lChild; Node *rChild
2013-06-26 21:24:35
400
原创 Quick Sort
// qkSort.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include #include #include #include using namespace std;static compare_int(const void *key1
2013-06-26 13:24:07
439
原创 Merge Sort
/*//implement recursivelyint mgSort( const void *data, int size, int esize, int i, int k, int (*comp) (const void *a, const void *b) );//merge 2 sequential partstatic int merge( const void *da
2013-06-25 12:00:56
440
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅