摘要:
header file#ifndef TRIE_H_INCLUDED
#define TRIE_H_INCLUDED #include
#include typedef struct trie
{ int words; int prefixes; struct trie *edges[26];
} trie; trie * initialize(trie *node);
trie * addWord(trie *ver,char *str);
int countWords(trie *ver,char *str);
int countPrefix(trie *ve... 阅读全文
随笔分类 - 程序算法
Python打印log,包括行号,路径,方法名,文件
2013-07-18 11:09 by java20130722, 3054 阅读, 收藏,
摘要:
logger.py 文件 #!/usr/bin/python # coding: utf-8 import logging import logging.handlers from logging import * from datetime import * logger = logging.getLogger() logger.setLevel(logging.DEBUG) rht = logging.handlers.TimedRotatingFileHandler("reindex_out.log", 'D') fmt = logging.Forma 阅读全文
自定义Java Annotations实例以及用Java Reflection来解析自定义的Annotation
2013-07-16 18:17 by java20130722, 331 阅读, 收藏,
摘要:
转自 http://www.journaldev.com/721/java-annotations-tutorial-with-custom-annotation-example-and-parsing-using-reflectionJava程序员都知道,在Java世界里到处可见@Override, @Deprecated等等这些Annotations, 这些代码不仅不影响Java代码编译运行,还能对代码起到很好的解释作用。那么我们如何定义自己的Annotation呐? 接下来就是很好的例子!package com.journaldev.annotations; import java... 阅读全文
自动机编程
2013-07-02 19:23 by java20130722, 1063 阅读, 收藏,
摘要:
摘自 维基百科自动机编程自动机编程(英语:Automata-based programming)是编程范型中的一种,是指程序或其中的部份是以有限状态机(FSM)为模型的程序,有些程序则会用其他型式(也更复杂)的自动机为其模型。有限状态机编程(英语:FSM-based programming)大致上等同于自动机编程,但有限状态机编程专指以有限状态机为模型的程序。自动机编程有以下的二项特征:程序运行的时间中可以清楚划分成数个自动机的步骤(step),每一个步骤即为一个程序区段,有单一的进入点,可以是一个函数或其他程序。若有需要时,程序区段可以再依其状态的不同,划分为子区段。不同步骤的程序区段只能通 阅读全文
计算方法之用变步长梯形求积公式求定积分
2013-06-11 13:02 by java20130722, 1203 阅读, 收藏,
摘要:
/*
*
* 用变步长梯形求积公式求定积分
* 1
* ∫ (x/(4+x^2))dx
* 0
*/ #include #include #include #include #include #define epsilon 0.00001 float f(float x)
{ return(x/(4+x*x));
} float computeT(float a,float b)
{ float T=0,h=(b-a)/2; T=h*(f(a)+2*T+f(b))/2; return(T);
} main()
{ int i;
... 阅读全文
计算方法之改进的欧拉法计算常微分方程
2013-06-11 13:01 by java20130722, 1027 阅读, 收藏,
摘要:
/***********************
* *改进的欧拉法计算常微分方程
* y'=(1/x)*y-(1/x)*y^2, 1
#include
#include float f(float x, float y) { return (y / x - y * y / x);
} float Euler(float x0, float xn, float y0, int n) { int i; float yp, yc, x = x0, y = y0, h; h = (xn - x0) / n; for (i = 1; i <= n; i++) { yp = y... 阅读全文
计算方法之用雅克比法求线性方程组
2013-06-11 12:59 by java20130722, 248 阅读, 收藏,
摘要:
/*************************************
* 用雅克比法求线性方程组
* * 5*x1 + 2*x2 + 1*x3 = -12
*{-1*x1 + 4*x2 + 2*x3 = 20
* 2*x1 - 3*x2 +10*x3 = 3
*
**************************************/
#include
#include
#include #define N 3
#define kmax 100
#define eps 1e-5 static double aa[N][N] = { { 5, 2, 1 }, { -1, ... 阅读全文
计算方法之用追赶法求线性方程组
2013-06-11 12:57 by java20130722, 535 阅读, 收藏,
摘要:
/*************************************
* 用追赶法求线性方程组
* * |- -| |- -| |- -|
* | 2 -1 | | x1 | | 3 |
* |-1 3 -2 | | x2 | | 1 |
* | -2 4 -2 |*| x3 | = | 0 |
* | -2 5 | | x4 | | -5 |
* |- -| |- -| |- -|
*
***************************... 阅读全文
计算方法之用高斯列主元消去法求线性方程组
2013-06-11 12:56 by java20130722, 501 阅读, 收藏,
摘要:
/*************************************
* 用高斯列主元消去法求线性方程组
* * 2*x1 + 2*x2 + 3*x3 = 3
*{4*x1 + 7*x2 + 7*x3 = 1
* -2*x1+ 4*x2 + 5*x3 = -7
*
**************************************/#include
#include
#include
#include #define N 3 int main() { static double a[N][N] = { { 2, 2, 3 }, { 4, 7, 7 }, { -2, 4... 阅读全文
计算方法之牛顿迭代法求方程根
2013-06-11 12:54 by java20130722, 551 阅读, 收藏,
摘要:
/*************************************
* 用牛顿迭代法求非线性方程
* f(x)=x-e^(-x)=0
* 在区间[0,1]的根,取ξ=10^(-5),x0 = 0.5
**************************************/
#include
#include
#include #define maxrept 1000 float f(float x) { return x - exp(-x);
}
float df(float x) { return 1 + exp(-x);
}
float iterate(float ... 阅读全文
计算方法之迭代法求方程根
2013-06-11 12:51 by java20130722, 602 阅读, 收藏,
摘要:
/************************
* 用迭代法求方程
* f(x)=e^(-x)-x+1=0
* 的根
*************************/
#include
#include
#include float fa(float);
float dd(float);
int main() { float x0; printf("input data x0 = "); scanf("%f", &x0); printf("The root of f(x) = 0 is x = \t%f\n", dd( 阅读全文
计算方法之二分法求方程根
2013-06-11 12:48 by java20130722, 856 阅读, 收藏,
摘要:
/************************
* 用二分法求方程
* f(x)=x^3-2x-5=0
* 在区间[2,3]内的根
*************************/
#include
#include
#include float f(float x) { float a; a = x * x * x - 2 * x - 5; return a;
}
int main() { float a, b, e, x; printf("\nplease input data a = "); scanf("%f", &a); pri 阅读全文
PageRank算法概述
2013-06-09 23:25 by java20130722, 242 阅读, 收藏,
摘要:
读书报告,转载请标明出处http://blog.csdn.net/wzhg0508/article/details/9068849 阅读全文
Lock-free 多核数据结构设计
2013-06-09 00:28 by java20130722, 279 阅读, 收藏,
摘要:
lock-free思想背景基本的多核数据结构设计是非常简单的:只需要在并发处理同一数据结构时,加上locks就可以了。这种思想在并发数不是很多的情况下工作的很好。因为这时的资源争用开销并不是很大。随着多核机器逐渐的变大变多,例如成百上千的核,这种加lock机制对此应用的不是很好:如果你只有几个锁,锁的争夺成为巨大的;如果你有许多细粒度的锁,锁的开销开始增加。所以对于大型多核机器来说,“Lock-free”的设计非常常见。以下这些策略基本覆盖了这种设计思想:1、我们不每次都是用lock,但只有当我们真的需要它们的时候(例如只写不读);2、我们不是每秒都用lock,但是我们可以自己构建相同的东西( 阅读全文
关于Lock-free Hash Table的一些链接资料
2013-06-08 09:09 by java20130722, 133 阅读, 收藏,
摘要:
链接http://preshing.com/20130505/introducing-mintomic-a-small-portable-lock-free-apihttp://preshing.com/20130605/the-worlds-simplest-lock-free-hash-tablehttp://preshing.com/20130529/a-lock-free-linear-search这些资料看了,而且还看了大神的PPT以及视频,确实不太懂。 阅读全文
浙公网安备 33010602011771号