最近,我读了这篇文章扔掉密钥:简单,最小的完美散列有关为一组已知的密钥生成最小的完美散列表。
本文似乎假设您需要一个中间表。如果我们假设键的集合很小(即<64),是否还有其他更简单的方法来生成这样的函数。
就我而言,我想将一组线程ID:s映射到数组中的唯一数据块。线程在生成哈希函数之前启动,并在程序运行期间保持不变。确切的线程数有所不同,但在程序运行时保持不变:
unsigned int thread_ids*;
unsigned int thread_count;
struct {
/* Some thread specific data */
}* ThreadData;
int start_threads () {
/* Code which starts the threads and allocates the threaddata. */
}
int f(thread_id) {
/* return unique index into threadData */
}
int main() {
thread_count = 64; /* This number will be small, e.g. < 64 */
start_threads();
ThreadData[f(thread_ids[0])]
}
Run Code Online (Sandbox Code Playgroud) 我有一个基本上这样做的程序
while(1)
FindFirstFile()
if file found
CreateFile()
DeleteFile()
Run Code Online (Sandbox Code Playgroud)
但是,有时CreateFile会报告ERROR_FILE_NOT_FOUND,即使FindFirstFile找到了一个文件!DeleteFile是否保证文件在返回后不会显示在目录列表中?
我使用的是Python 2.5
我有一个角度(以弧度为单位)。我想将其四舍五入到最接近的四分之一圆。因此,例如:
def round_quarter_angle(a):
pass
round_quarter_angle(3) # == math.pi (3.1415926535897931)
round_quarter_angle(1.4) # == math.pi / 2 (1.5707963267948966)
round_quarter_angle(6) # == 0
Run Code Online (Sandbox Code Playgroud)