@ -11,12 +11,12 @@ import (
func TestSegmentBsearchKey ( t * testing . T ) {
testSegment := & CompactMapSegment {
list : [ ] NeedleValue {
NeedleValue { K ey: 10 } ,
NeedleValue { K ey: 20 } ,
NeedleValue { K ey: 21 } ,
NeedleValue { K ey: 26 } ,
NeedleValue { K ey: 30 } ,
list : [ ] Compact NeedleValue{
Compact NeedleValue{ k ey: 10 } ,
Compact NeedleValue{ k ey: 20 } ,
Compact NeedleValue{ k ey: 21 } ,
Compact NeedleValue{ k ey: 26 } ,
Compact NeedleValue{ k ey: 30 } ,
} ,
firstKey : 10 ,
lastKey : 30 ,
@ -116,10 +116,10 @@ func TestSegmentBsearchKey(t *testing.T) {
func TestSegmentSet ( t * testing . T ) {
testSegment := & CompactMapSegment {
list : [ ] NeedleValue {
NeedleValue { K ey: 10 , O ffset: types . Uint32ToOffset ( 0 ) , S ize: 100 } ,
NeedleValue { K ey: 20 , O ffset: types . Uint32ToOffset ( 100 ) , S ize: 200 } ,
NeedleValue { K ey: 30 , O ffset: types . Uint32ToOffset ( 300 ) , S ize: 300 } ,
list : [ ] Compact NeedleValue{
Compact NeedleValue{ k ey: 10 , o ffset: OffsetToCompact ( types . Uint32ToOffset ( 0 ) ) , s ize: 100 } ,
Compact NeedleValue{ k ey: 20 , o ffset: OffsetToCompact ( types . Uint32ToOffset ( 100 ) ) , s ize: 200 } ,
Compact NeedleValue{ k ey: 30 , o ffset: OffsetToCompact ( types . Uint32ToOffset ( 300 ) ) , s ize: 300 } ,
} ,
firstKey : 10 ,
lastKey : 30 ,
@ -173,13 +173,13 @@ func TestSegmentSet(t *testing.T) {
}
wantSegment := & CompactMapSegment {
list : [ ] NeedleValue {
NeedleValue { K ey: 5 , O ffset: types . Uint32ToOffset ( 1000 ) , S ize: 123 } ,
NeedleValue { K ey: 10 , O ffset: types . Uint32ToOffset ( 0 ) , S ize: 100 } ,
NeedleValue { K ey: 20 , O ffset: types . Uint32ToOffset ( 100 ) , S ize: 200 } ,
NeedleValue { K ey: 25 , O ffset: types . Uint32ToOffset ( 8000 ) , S ize: 789 } ,
NeedleValue { K ey: 30 , O ffset: types . Uint32ToOffset ( 9000 ) , S ize: 999 } ,
NeedleValue { K ey: 51 , O ffset: types . Uint32ToOffset ( 7000 ) , S ize: 456 } ,
list : [ ] Compact NeedleValue{
Compact NeedleValue{ k ey: 5 , o ffset: OffsetToCompact ( types . Uint32ToOffset ( 1000 ) ) , s ize: 123 } ,
Compact NeedleValue{ k ey: 10 , o ffset: OffsetToCompact ( types . Uint32ToOffset ( 0 ) ) , s ize: 100 } ,
Compact NeedleValue{ k ey: 20 , o ffset: OffsetToCompact ( types . Uint32ToOffset ( 100 ) ) , s ize: 200 } ,
Compact NeedleValue{ k ey: 25 , o ffset: OffsetToCompact ( types . Uint32ToOffset ( 8000 ) ) , s ize: 789 } ,
Compact NeedleValue{ k ey: 30 , o ffset: OffsetToCompact ( types . Uint32ToOffset ( 9000 ) ) , s ize: 999 } ,
Compact NeedleValue{ k ey: 51 , o ffset: OffsetToCompact ( types . Uint32ToOffset ( 7000 ) ) , s ize: 456 } ,
} ,
firstKey : 5 ,
lastKey : 51 ,
@ -213,7 +213,7 @@ func TestSegmentSetOrdering(t *testing.T) {
t . Errorf ( "expected size %d, got %d" , want , got )
}
for i := 1 ; i < cs . len ( ) ; i ++ {
if ka , kb := cs . list [ i - 1 ] . K ey, cs . list [ i ] . K ey; ka >= kb {
if ka , kb := cs . list [ i - 1 ] . k ey, cs . list [ i ] . k ey; ka >= kb {
t . Errorf ( "found out of order entries at (%d, %d) = (%d, %d)" , i - 1 , i , ka , kb )
}
}
@ -221,10 +221,10 @@ func TestSegmentSetOrdering(t *testing.T) {
func TestSegmentGet ( t * testing . T ) {
testSegment := & CompactMapSegment {
list : [ ] NeedleValue {
NeedleValue { K ey: 10 , O ffset: types . Uint32ToOffset ( 0 ) , S ize: 100 } ,
NeedleValue { K ey: 20 , O ffset: types . Uint32ToOffset ( 100 ) , S ize: 200 } ,
NeedleValue { K ey: 30 , O ffset: types . Uint32ToOffset ( 300 ) , S ize: 300 } ,
list : [ ] Compact NeedleValue{
Compact NeedleValue{ k ey: 10 , o ffset: OffsetToCompact ( types . Uint32ToOffset ( 0 ) ) , s ize: 100 } ,
Compact NeedleValue{ k ey: 20 , o ffset: OffsetToCompact ( types . Uint32ToOffset ( 100 ) ) , s ize: 200 } ,
Compact NeedleValue{ k ey: 30 , o ffset: OffsetToCompact ( types . Uint32ToOffset ( 300 ) ) , s ize: 300 } ,
} ,
firstKey : 10 ,
lastKey : 30 ,
@ -233,7 +233,7 @@ func TestSegmentGet(t *testing.T) {
testCases := [ ] struct {
name string
key types . NeedleId
wantValue * NeedleValue
wantValue * Compact NeedleValue
wantFound bool
} {
{
@ -277,11 +277,11 @@ func TestSegmentGet(t *testing.T) {
func TestSegmentDelete ( t * testing . T ) {
testSegment := & CompactMapSegment {
list : [ ] NeedleValue {
NeedleValue { K ey: 10 , O ffset: types . Uint32ToOffset ( 0 ) , S ize: 100 } ,
NeedleValue { K ey: 20 , O ffset: types . Uint32ToOffset ( 100 ) , S ize: 200 } ,
NeedleValue { K ey: 30 , O ffset: types . Uint32ToOffset ( 300 ) , S ize: 300 } ,
NeedleValue { K ey: 40 , O ffset: types . Uint32ToOffset ( 600 ) , S ize: 400 } ,
list : [ ] Compact NeedleValue{
Compact NeedleValue{ k ey: 10 , o ffset: OffsetToCompact ( types . Uint32ToOffset ( 0 ) ) , s ize: 100 } ,
Compact NeedleValue{ k ey: 20 , o ffset: OffsetToCompact ( types . Uint32ToOffset ( 100 ) ) , s ize: 200 } ,
Compact NeedleValue{ k ey: 30 , o ffset: OffsetToCompact ( types . Uint32ToOffset ( 300 ) ) , s ize: 300 } ,
Compact NeedleValue{ k ey: 40 , o ffset: OffsetToCompact ( types . Uint32ToOffset ( 600 ) ) , s ize: 400 } ,
} ,
firstKey : 10 ,
lastKey : 40 ,
@ -317,11 +317,11 @@ func TestSegmentDelete(t *testing.T) {
}
wantSegment := & CompactMapSegment {
list : [ ] NeedleValue {
NeedleValue { K ey: 10 , O ffset: types . Uint32ToOffset ( 0 ) , S ize: 100 } ,
NeedleValue { K ey: 20 , O ffset: types . Uint32ToOffset ( 100 ) , S ize: - 200 } ,
NeedleValue { K ey: 30 , O ffset: types . Uint32ToOffset ( 300 ) , S ize: 300 } ,
NeedleValue { K ey: 40 , O ffset: types . Uint32ToOffset ( 600 ) , S ize: - 400 } ,
list : [ ] Compact NeedleValue{
Compact NeedleValue{ k ey: 10 , o ffset: OffsetToCompact ( types . Uint32ToOffset ( 0 ) ) , s ize: 100 } ,
Compact NeedleValue{ k ey: 20 , o ffset: OffsetToCompact ( types . Uint32ToOffset ( 100 ) ) , s ize: - 200 } ,
Compact NeedleValue{ k ey: 30 , o ffset: OffsetToCompact ( types . Uint32ToOffset ( 300 ) ) , s ize: 300 } ,
Compact NeedleValue{ k ey: 40 , o ffset: OffsetToCompact ( types . Uint32ToOffset ( 600 ) ) , s ize: - 400 } ,
} ,
firstKey : 10 ,
lastKey : 40 ,
@ -343,8 +343,9 @@ func TestSegmentForKey(t *testing.T) {
name : "first segment" ,
key : 12 ,
want : & CompactMapSegment {
list : [ ] NeedleValue { } ,
firstKey : SegmentChunkSize - 1 ,
list : [ ] CompactNeedleValue { } ,
chunk : 0 ,
firstKey : MaxCompactKey ,
lastKey : 0 ,
} ,
} ,
@ -352,18 +353,20 @@ func TestSegmentForKey(t *testing.T) {
name : "second segment, gapless" ,
key : SegmentChunkSize + 34 ,
want : & CompactMapSegment {
list : [ ] NeedleValue { } ,
firstKey : ( 2 * SegmentChunkSize ) - 1 ,
lastKey : SegmentChunkSize ,
list : [ ] CompactNeedleValue { } ,
chunk : 1 ,
firstKey : MaxCompactKey ,
lastKey : 0 ,
} ,
} ,
{
name : "gapped segment" ,
key : ( 5 * SegmentChunkSize ) + 56 ,
want : & CompactMapSegment {
list : [ ] NeedleValue { } ,
firstKey : ( 6 * SegmentChunkSize ) - 1 ,
lastKey : 5 * SegmentChunkSize ,
list : [ ] CompactNeedleValue { } ,
chunk : 5 ,
firstKey : MaxCompactKey ,
lastKey : 0 ,
} ,
} ,
}
@ -380,19 +383,22 @@ func TestSegmentForKey(t *testing.T) {
wantMap := & CompactMap {
segments : map [ int ] * CompactMapSegment {
0 : & CompactMapSegment {
list : [ ] NeedleValue { } ,
firstKey : SegmentChunkSize - 1 ,
list : [ ] CompactNeedleValue { } ,
chunk : 0 ,
firstKey : MaxCompactKey ,
lastKey : 0 ,
} ,
1 : & CompactMapSegment {
list : [ ] NeedleValue { } ,
firstKey : ( 2 * SegmentChunkSize ) - 1 ,
lastKey : SegmentChunkSize ,
list : [ ] CompactNeedleValue { } ,
chunk : 1 ,
firstKey : MaxCompactKey ,
lastKey : 0 ,
} ,
5 : & CompactMapSegment {
list : [ ] NeedleValue { } ,
firstKey : ( 6 * SegmentChunkSize ) - 1 ,
lastKey : 5 * SegmentChunkSize ,
list : [ ] CompactNeedleValue { } ,
chunk : 5 ,
firstKey : MaxCompactKey ,
lastKey : 0 ,
} ,
} ,
}