Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / simpletun.c
Created April 27, 2015 09:08
一个简单的使用tun/tap建立tunnel的示例代码
/**************************************************************************
* simpletun.c *
* *
* A simplistic, simple-minded, naive tunnelling program using tun/tap *
* interfaces and TCP. Handles (badly) IPv4 for tun, ARP and IPv4 for *
* tap. DO NOT USE THIS PROGRAM FOR SERIOUS PURPOSES. *
* *
* You have been warned. *
* *
* (C) 2009 Davide Brini. *
@rickyzhang-cn
rickyzhang-cn / skiplist.c
Created April 27, 2015 12:02
skiplist的一个C实现
/* ======================================================================
* Copyright (c) 2000,2006 Theo Schlossnagle
* All rights reserved.
* The following code was written by Theo Schlossnagle for use in the
* Backhand project at The Center for Networking and Distributed Systems
* at The Johns Hopkins University.
*
* This is a skiplist implementation to be used for abstract structures
* and is release under the LGPL license version 2.1 or later. A copy
* of this license can be found file LGPL.
@rickyzhang-cn
rickyzhang-cn / simple_lru.cpp
Created May 8, 2015 02:12
A simple lru implementation with c++
// A simple LRU cache written in C++
// Hash map + doubly linked list
#include <iostream>
#include <vector>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
template <class K, class T>
struct Node{
@rickyzhang-cn
rickyzhang-cn / lis.cpp
Created May 8, 2015 07:12
Longest Increasing Subsequence
#include <iostream>
using namespace std;
int lis(int A[], int n){
int *d = new int[n];
int len = 1;
for(int i=0; i<n; ++i){
d[i] = 1;
for(int j=0; j<i; ++j)
if(A[j]<=A[i] && d[j]+1>d[i])