儲存鍵值對id:value值
儲存100萬資料對
查詢value區間,比如10到100;個數?
查詢id區間,比如10到100;個數?
查詢某id或某value,排名第幾?
在跳表實體加個索引號;
skiplist skiplist = new skiplist();
skiplist.put(5, 5);
skiplist.put(55, 55);
skiplist.put(45, 45);
skiplist.put(35, 35);
skiplist.put(25, 25);
skiplist.put(15, 15);
skiplist.put(53, 53);
system.out.println(skiplist.countbyvaluerange(15,53));
skiplist.doprintln();
跳表實體:
public class skiplistentry
public integer getkey()
public v getvalue()
}跳表列表:
public class skiplist
public skiplistentrygetskiplistentry(integer key)
if(p.down != null)else
}return p;
}public v get(integer key)else
}public void put(integer key,v value)
while(target!=this.head&&target.up==null)
target = target.up;
skiplistentry skiplistentry = new skiplistentry(key,value);
skiplistentry.left = target;
skiplistentry.right = target.right;
skiplistentry.down = newtarget;
skiplistentry.indexcurrent = newtarget.indexcurrent;
newtarget.up = skiplistentry;
target.right.left = skiplistentry;
target.right = skiplistentry;
currentlevel++;
}size++;
}public void doprintln()
while(skiplistentry.right!=null)
system.out.println(skiplistentry.key+":"+skiplistentry.value + ":" + skiplistentry.indexcurrent);
}public void doaddindex(skiplistentrytarget)
temp = temp.right;}}
public skiplistentry getskiplistentrybyvalue(integer value)
if(current.down!=null)else
}return current;
}public int countbyvaluerange(int startvalue,int endvalue)
}
資料結構之跳表
字典有一些形如 字典的節點 鍊錶節點定義 template struct pairnode pairnode const pair element element element pairnode const pair element,pairnode next element element 字典...
redis 資料結構 跳表
要先有跳表的資料結構基礎 跳表是鍊錶的乙個變種,通過增加多餘的指標,將單向鍊錶變成多向鍊錶,進而使跳表的查詢效率和平衡二叉樹看齊 平均o logn 最壞o n 而且較之二叉樹實現方便。而跳表本身,有一些比較迷的實現策略 比如,新增節點的層次是通過隨機數 拋硬幣 指定的,存在乙個隨機概率,這在redi...
資料結構 跳表(Skip List)
從頂層鍊錶的首元素開始,從左往右搜尋,知道找到乙個大於或等於目標的元素,或者到達當前層鍊錶的尾部 如果該元素等於目標元素,則表明該元素已被找到 如果該元素大於目標元素或已到達鍊錶的尾部,則退回到當前層的前乙個元素,然後轉入下一層進行搜尋 新節點的層數 int newlevel randomlevel...