由买买提看人间百态

topics

全部话题 - 话题: serverid
(共0页)
B********4
发帖数: 7156
1
来自主题: JobHunting版 - 大家看看我哪道题做错了?
Amazon的电面online test挂了。很纳闷,因为我觉得题不难,当时还以为自己都做对
了呢。大家看看我哪道题做错了?
1)给一段代码,用queue实现对binary tree的遍历。问time complexity and space
complexity.
我一看,这不是BFS吗,答O(n) and O(n)。
2)一段代码,在sorted array number[]里查找某个值。代码用的递归,每次比较目标
值和number[(min+max)/2],然后根据比较结果决定是min+1或者max-1.
我看每次递归只是array index范围缩小一个。所以答O(n)。
3)有一个online server 群,要求实现3个方法:
add(serverId): 添加一个新server,
remove(serverId):去掉一个server,
get(): 随机返回一个online server ID.提示可以用Random.random(i).
并要求所有方法time complexity 必须为O(1).
我想,必须用Hashtable来实现OnlineServers。我... 阅读全帖
p******s
发帖数: 938
2
来自主题: Unix版 - 求助:pthread_create的用法
使用pthread_create()出错,以下是测试用的代码:
void *ServerThread(void *arg1)
{
printf("I'm the server\n");
}

int main()
{
pthread_t serverID;
pthread_mutex_init(&lock, NULL);
printf("Now creating the thread to serve..\n");
if(pthread_create(&serverID, NULL, ServerThread, NULL)!=0)
perror("Could not create the thread\n");
pthread_join(serverID, NULL);
exit(0);
}
运行结果:
Now creating the thread to serve..
Could not create the thread
请问是为何出错?//bow
h****e
发帖数: 2125
3
来自主题: Programming版 - Best practice for updating user data?
hash_map >
typedef hash_map >::iterator itertype;
hash_map
u only need to search userid once to find all user ids on a server. need to
be careful with update methods though. not sure whether this is what u want.
..

出一个user
用户的区
样的
z***e
发帖数: 5393
4
来自主题: Programming版 - Best practice for updating user data?
嗯,差不多是这个意思,但是就象你说的,update的时候会比较messy,整个table都要
lock住?
还有就是具体需求并不是找list,而是在list里面找符合某些条件的。
我问的意思是这种先通过userid找serverid,然后再在在一个list里面iterate的做法
,是否有更
好的解决方案?

to
want.
(共0页)