资源简介
P2P 经典算法chord
Java编写
可以很好帮助大家学习。
代码片段和文件信息
//
// Chord1
// 僼儔僢僩側Chord
// 僲乕僪枅偵儕僼儗僢僔儏娫妘丄嶲壛扙戅娫妘丄query娫妘傪愝掕偱偒偰偄側偄
// hash_max偼戝偒側抣偲偟丄偦傟傛傝彫偝側抣傪嶲壛僲乕僪悢偲偡傞
// 棟桼丗嶲壛丒扙戅傪偟偨偲偒丄hash_max偑嫹偄偲丄摨偠ID偱嶲壛偡傞僲乕僪偑
// 偱偒傞丅偦傟偱偼丄refresh傪偟側偔偰傕丄惉岟偟偰偟傑偆丅
// 儕僼儗僢僔儏傪崅昿搙偱偟側偄偲丄惉岟偟側偄傛偆偵偡傞偵偼丄join
// 偡傞僲乕僪偑偱偒傞偩偗堎側傞ID偲側傞傛偆偵偡傞昁梫偑偁傞丅
// 廬偭偰丄hash_max傪戝偒偔偡傞昁梫偑偁傞丅
//
//
//import java.io.*;
import java.util.*;
////////////////////////////////////////////////////////////////////////////
class Event{
long node_id; /* node ID */
int event_type; /* 1: join node 2: delete node 3: join_req 4: delete_req
5: query_req 6: reply 7: ID list refresh 8: ?*/
int seen; /* seen query flag */
int hop; /* Number of hops */
long new_node_id; /* sanka node id */
long delete_node_id; /* dattai node id */
long query_id; /* Query code */
long query_node_id; /* initiator of Query */
long reply_type; /* 0: OK 1: NG */
long reply_node; /* sender of reply */
double etime; /* occured time */
long sender; /*define a transformer*/
}
//////////////////////////////////////////////////////////////////////////
class zipf{
int cache_id;
int cache_num;
}
////////////////////////////////////////////////////////////////////////
class Cache{
long cache_id;// cache id
double time_limit;// time limit
}
/////////////////////////////////////////////////////////////////////////////
public class chord1{
static final int HASH_MAX = 32768; // Hash space size 2^15
static final int HOP_MAX = 20; // Max number of hops of query
static final int E_JOINNODE = 1;
static final int E_DELENODE = 2;
static final int E_JOINNREQ = 3;
static final int E_DELENREQ = 4;
static final int E_QUERYREQ = 5;
static final int E_REPLYREQ = 6;
static final int E_REFRESH = 7;
static final int E_CACHE = 8;
static final float END_TIME = 180000.0F;
static final float QUERY_INTERVAL = 200.0F ;
static final float REFRESH_INTERVAL = 1000.0F;
static final float JOIN_DEL_INTERVAL = 10000.0F;
static final float DELAY = 0.01F;
static final int INITIALNODE =512;
static final int MAXQUERY = 100000;
static final double CACHERATE = 0;
static final double CACHELIMIT = 30;
static final boolean CACHE_OF_CACHE = false;//create “cache of cache“ or not
static int node_cache_count[] = new int[HASH_MAX];
static double time = 0.0;
static double l_time;
static long total_query = 0;
static long total_success = 0;
static long total_fail = 0;
static long total_fail1 = 0;
static long total_fail2 = 0;
static long total_fail_timeover = 0;
static long total_join = 0;
static long total_delete = 0;
static long total_hop = 0;
static long total_hit = 0;
static long total_refresh =0;
static Vector sched;
static Vector node;
static Random rr1r2;
static int queue = 0;
static Event top current;
static float refresh_int[] = new float[HASH_MAX]; // 2048 is HASH_MAX
static float query_int[] =
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 301 2011-09-12 15:07 chord\.classpath
文件 381 2011-09-12 15:07 chord\.project
文件 629 2011-09-12 15:07 chord\.settings\org.eclipse.jdt.core.prefs
文件 289 2013-11-30 17:43 chord\bin\Cache.class
文件 10537 2013-11-30 17:43 chord\bin\chord1.class
文件 486 2013-11-30 17:43 chord\bin\Event.class
文件 5141 2013-11-30 17:43 chord\bin\NodeInstance.class
文件 1679 2013-11-30 17:43 chord\bin\Solution.class
文件 282 2013-11-30 17:43 chord\bin\zipf.class
文件 20622 2012-01-20 11:49 chord\src\chord1.java
文件 9982 2012-01-16 09:35 chord\src\NodeInstance.java
文件 1147 2013-09-11 20:35 chord\src\Solution.java
目录 0 2011-09-12 15:07 chord\.settings
目录 0 2013-11-30 17:43 chord\bin
目录 0 2013-09-11 19:31 chord\src
目录 0 2011-09-12 15:07 chord
----------- --------- ---------- ----- ----
51476 16
评论
共有 条评论