Skip to content

Instantly share code, notes, and snippets.

@rickyzhang-cn
rickyzhang-cn / Makefile
Created January 9, 2015 04:45
Linux内核rbtree实现的移植
all:rbtree-tst
CFLAGS=-g -O0 -Wall
rbtree-tst:rbtree-tst.o rbtree.o
rbtree.o:rbtree.h rbtree.c
rbtree-tst.o:rbtree-tst.c
@rickyzhang-cn
rickyzhang-cn / main.c
Created January 6, 2015 12:44
Reactor模式示例代码
#include <arpa/inet.h>
#include <unistd.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/epoll.h>
#include <sys/types.h>
#include <pthread.h>
@rickyzhang-cn
rickyzhang-cn / heap.c
Created January 6, 2015 12:36
Priority Queue实现代码
#include <stdlib.h>
#include <stdio.h>
#include "heap.h"
PriorityQueue pq_init(int capacity)
{
PriorityQueue H;
H=(PriorityQueue )malloc(sizeof(struct HeapStruct));
@rickyzhang-cn
rickyzhang-cn / hash.c
Created January 6, 2015 12:25
Pintos中hash table的实现代码
/* Hash table.
This data structure is thoroughly documented in the Tour of
Pintos for Project 3.
See hash.h for basic information. */
#include "hash.h"
#include "../debug.h"
#include "threads/malloc.h"
@rickyzhang-cn
rickyzhang-cn / list.c
Created December 10, 2014 13:02
Pintos中的双线链表实现代码
#include "list.h"
#include "../debug.h"
/* Our doubly linked lists have two header elements: the "head"
just before the first element and the "tail" just after the
last element. The `prev' link of the front header is null, as
is the `next' link of the back header. Their other two links
point toward each other via the interior elements of the list.
An empty list looks like this:
@rickyzhang-cn
rickyzhang-cn / netBuffLib.c
Created November 7, 2014 12:06
VxWorks下netBuffLib的实现代码
/* netBufLib.c - network buffer library */
/* Copyright 1984 - 2001 Wind River Systems, Inc. */
/*
modification history
--------------------
01r,07may02,kbw man page edits
01q,15oct01,rae merge from truestack ver 01w, base 01n (SPR #65195 etc.)
@rickyzhang-cn
rickyzhang-cn / rngLib.c
Created November 7, 2014 12:03
VxWorks下rngLib的实现代码
/* rngLib.c - ring buffer subroutine library */
/* Copyright 1984-1995 Wind River Systems, Inc. */
/*
modification history
--------------------
01x,13feb95,jdi doc tweaks.
01w,20jan93,jdi documentation cleanup for 5.1.
@rickyzhang-cn
rickyzhang-cn / main.c
Last active August 29, 2015 14:08
仿照linux kfifo写的ring buffer
/**@brief ring buffer测试程序,创建两个线程,一个生产者,一个消费者。
* 生产者每隔1秒向buffer中投入数据,消费者每隔2秒去取数据。
*@atuher Anker date:2013-12-18
* */
#include "ring_buffer.h"
#include <pthread.h>
#include <time.h>
#define BUFFER_SIZE 1024 * 1024
@rickyzhang-cn
rickyzhang-cn / merge_sort.c
Created October 20, 2014 13:42
排序算法的C实现
#include <stdio.h>
#include <stdlib.h>
void merge(int a[], int temp_array[], int l_pos, int r_pos, int end)
{
int i=0;
int j;
int l=l_pos,r=r_pos;
while(l<r_pos && r<=end)
{
@rickyzhang-cn
rickyzhang-cn / avl_tree.c
Created October 20, 2014 13:40
AVL Tree的C实现
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "avl_tree.h"
static Position SingleRotateWithRight(Position K2);
static int Height(Position P)
{
if(P == NULL)