Hash table

Posted on Sun 28 November 2010 in miscLeave a comment

Hash table定义(摘自wikidpedia)\ In computer science, a hash table or hash map is a data structure that uses a hash function to map identifying values, known as keys (e.g., a person's name), to their associated values (e.g., their telephone number).\ hash table简单来说就是一种数据结构,可以通过一个key来查询对应的value值(一般情况下效率是很高的)。

记得以前大学时,老师曾出过这样的一道题目 ...

Continue reading

最大流与最小割

Posted on Fri 26 November 2010 in miscLeave a comment

最大流与最小割定义(摘自wikipedia)\ In optimization theory, the max-flow min-cut theorem states that in a flow network, the maximum amount of flow passing from the source to the sink is equal to the minimum capacity which when removed in a specific way from the network causes the situation that no flow ...

Continue reading

二分图最大匹配

Posted on Tue 23 November 2010 in miscLeave a comment

二分图定义(摘自wiki)\ In the mathematical field of graph theory, a bipartite graph (or bigraph) is a graph whose vertices can be divided into two disjoint sets U and V such that every edge connects a vertex in U to one in V; that is, U and V are independent sets ...

Continue reading

python解析html

Posted on Wed 10 November 2010 in miscLeave a comment

python自带有一个html的解析库,但这个库的功能有限,而且对网页中异常情况的处理不好。\ 后来在网上找到一个叫[BeautifulSoup](http://www.crummy.com/software/BeautifulSoup/)的网页解析库,这个库利用了正则表达式对网页进行处理,能比较完美地处理异常情况,还支持unicode。\ 除此之外还有lxml等python库。\ 下面是BeautifulSoup的一些例子,是从官网摘过来的。更多详细信息可以看[官方文档](http://www.crummy.com/software/BeautifulSoup/documentation.html),有[中文版](http://www.crummy.com/software/BeautifulSoup/documentation.zh.html)\

Continue reading

判断两个路径(文件或文件夹)所指的内容是否相同

Posted on Mon 25 October 2010 in miscLeave a comment

思路:\ 1.判断文件是否都存在\ 2.判断类型是否相同(是否都是文件夹,是否都是文件)\ 3.如果是文件, 比较文件的二进制内容\ 4.如果是文件夹:\ 4.1 列出文件夹下的所有文件,并按文件名排序\ 4.2 依次递归比较所有文件

代码:\

Continue reading

python实现daemon程序

Posted on Thu 21 October 2010 in miscLeave a comment

为了实现python程序的daemon运行,找到了如下的代码。通过继承这个类,就能实现daemon程序。\ 除此之外还可以用screen,或nohup来实现。\ 代码出处:http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/

import sys, os, time, atexit
from signal import SIGTERM

class Daemon:
    """
   A generic daemon class.

 Usage: subclass the Daemon class and override the run() method
    """
   def __init__(self, pidfile, stdin='/dev/null', stdout='/dev/null ...
Continue reading

获取自增长id(mysql)

Posted on Wed 20 October 2010 in miscLeave a comment

java

PreparedStatement ps =conn.prepareStatement("insert into table (col) values (?)", Statement.RETURN_GENERATED_KEYS);
ps.getGeneratedKeys();

sql

最后插入的id

select last_insert_id();

下一个id

SHOW TABLE STATUS LIKE "table_name";//auto_increment列
Continue reading

ttserver相关

Posted on Wed 20 October 2010 in miscLeave a comment

ttserver在32位机器上支持超过4g的数据库,编译时加上如下的选项:\ --enbale-off64

Continue reading

当前目录和程序所在目录

Posted on Wed 20 October 2010 in miscLeave a comment

1.python\ 当前目录:

import os
os.getcwd()

程序所在目录:

import os
#os.path.split( os.path.realpath( sys.argv[0] ) )[0]
os.path.dirname(os.path.realpath(__file__))

2.vc/mfc\ 当前目录:

TCHAR path[MAX_PATH];
GetCurrentDirectory(path, MAX_PATH);

程序所在目录:

TCHAR path[MAX_PATH];
GetModuleFileName(NULL, path, MAX_PATH);

3.c/c++(linux)\ 当前目录 ...

Continue reading

确保FileOutputStream将内容写入硬盘

Posted on Thu 14 October 2010 in miscLeave a comment

最近写了一个程序,需要在数据写入文件后立即读取该文件内容。这一简单的功能,却会时不时抛异常,令我十分不解。

原程序如下:\

FileOutputStream os = new FileOutputStream("some_file");\ os.write(data);\ os.close();

在查了jdk中关于flush()函数的介绍后,发现了一些问题。flush只保证数据已交付给了操作系统,无法确定已写入硬盘。

以下是jdk中关于flush()函数的介绍:\

Flushes this output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that ...

Continue reading