@@ -38,6 +38,7 @@ const initCacheWithComputedOffsets = (
3838 return acc ;
3939 } , [ ] as number [ ] ) ,
4040 _defaultItemSize : defaultSize ,
41+ _gap : 0 ,
4142 } ;
4243} ;
4344
@@ -51,6 +52,7 @@ const initCacheWithEmptyOffsets = (
5152 _computedOffsetIndex : - 1 ,
5253 _offsets : range ( sizes . length , ( ) => - 1 ) ,
5354 _defaultItemSize : defaultSize ,
55+ _gap : 0 ,
5456 } ;
5557} ;
5658
@@ -68,6 +70,7 @@ const initCacheWithOffsets = (
6870 _computedOffsetIndex : offsets . findIndex ( ( o ) => o === - 1 ) - 1 ,
6971 _offsets : [ ...offsets ] ,
7072 _defaultItemSize : defaultSize ,
73+ _gap : 0 ,
7174 } ;
7275} ;
7376
@@ -306,6 +309,7 @@ describe(computeTotalSize.name, () => {
306309 _computedOffsetIndex : 2 ,
307310 _offsets : offsets ,
308311 _defaultItemSize : 30 ,
312+ _gap : 0 ,
309313 } ;
310314 expect ( computeTotalSize ( cache ) ) . toBe ( sum ( range ( 8 , ( ) => 20 ) ) + 22 ) ;
311315 expect ( cache . _offsets ) . toEqual ( [
@@ -322,6 +326,7 @@ describe(computeTotalSize.name, () => {
322326 _computedOffsetIndex : 9 ,
323327 _offsets : offsets ,
324328 _defaultItemSize : 30 ,
329+ _gap : 0 ,
325330 } ;
326331 expect ( computeTotalSize ( cache ) ) . toBe ( 99 + 20 ) ;
327332 expect ( cache . _offsets ) . toEqual ( [ 0 , 11 , 22 , 33 , 44 , 55 , 66 , 77 , 88 , 99 ] ) ;
@@ -729,11 +734,12 @@ describe(estimateDefaultItemSize.name, () => {
729734describe ( initCache . name , ( ) => {
730735 it ( "should create cache" , ( ) => {
731736 const itemLength = 10 ;
732- const cache = initCache ( itemLength , 23 ) ;
737+ const cache = initCache ( itemLength , 23 , 0 ) ;
733738 expect ( cache ) . toMatchInlineSnapshot ( `
734739 {
735740 "_computedOffsetIndex": -1,
736741 "_defaultItemSize": 23,
742+ "_gap": 0,
737743 "_length": 10,
738744 "_offsets": [
739745 -1,
@@ -768,53 +774,55 @@ describe(initCache.name, () => {
768774
769775 it ( "should restore cache from snapshot" , ( ) => {
770776 const itemLength = 10 ;
771- const cache = initCache ( itemLength , 23 , [
777+ const cache = initCache ( itemLength , 23 , 0 , [
772778 [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ,
773779 123 ,
774780 ] ) ;
775781 expect ( cache ) . toMatchInlineSnapshot ( `
776- {
777- "_computedOffsetIndex": -1,
778- "_defaultItemSize": 123,
779- "_length": 10,
780- "_offsets": [
781- -1,
782- -1,
783- -1,
784- -1,
785- -1,
786- -1,
787- -1,
788- -1,
789- -1,
790- -1,
791- ],
792- "_sizes": [
793- 0,
794- 1,
795- 2,
796- 3,
797- 4,
798- 5,
799- 6,
800- 7,
801- 8,
802- 9,
803- ],
804- }
805- ` ) ;
782+ {
783+ "_computedOffsetIndex": -1,
784+ "_defaultItemSize": 123,
785+ "_gap": 0,
786+ "_length": 10,
787+ "_offsets": [
788+ -1,
789+ -1,
790+ -1,
791+ -1,
792+ -1,
793+ -1,
794+ -1,
795+ -1,
796+ -1,
797+ -1,
798+ ],
799+ "_sizes": [
800+ 0,
801+ 1,
802+ 2,
803+ 3,
804+ 4,
805+ 5,
806+ 6,
807+ 7,
808+ 8,
809+ 9,
810+ ],
811+ }
812+ ` ) ;
806813 expect ( cache . _length ) . toBe ( itemLength ) ;
807814 expect ( cache . _sizes . length ) . toBe ( itemLength ) ;
808815 expect ( cache . _offsets . length ) . toBe ( itemLength ) ;
809816 } ) ;
810817
811818 it ( "should restore cache from snapshot which has shorter length" , ( ) => {
812819 const itemLength = 10 ;
813- const cache = initCache ( itemLength , 23 , [ [ 0 , 1 , 2 , 3 , 4 ] , 123 ] ) ;
820+ const cache = initCache ( itemLength , 23 , 0 , [ [ 0 , 1 , 2 , 3 , 4 ] , 123 ] ) ;
814821 expect ( cache ) . toMatchInlineSnapshot ( `
815822 {
816823 "_computedOffsetIndex": -1,
817824 "_defaultItemSize": 123,
825+ "_gap": 0,
818826 "_length": 10,
819827 "_offsets": [
820828 -1,
@@ -849,41 +857,42 @@ describe(initCache.name, () => {
849857
850858 it ( "should restore cache from snapshot which has longer length" , ( ) => {
851859 const itemLength = 10 ;
852- const cache = initCache ( itemLength , 23 , [
860+ const cache = initCache ( itemLength , 23 , 0 , [
853861 [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 ] ,
854862 123 ,
855863 ] ) ;
856864 expect ( cache ) . toMatchInlineSnapshot ( `
857- {
858- "_computedOffsetIndex": -1,
859- "_defaultItemSize": 123,
860- "_length": 10,
861- "_offsets": [
862- -1,
863- -1,
864- -1,
865- -1,
866- -1,
867- -1,
868- -1,
869- -1,
870- -1,
871- -1,
872- ],
873- "_sizes": [
874- 0,
875- 1,
876- 2,
877- 3,
878- 4,
879- 5,
880- 6,
881- 7,
882- 8,
883- 9,
884- ],
885- }
886- ` ) ;
865+ {
866+ "_computedOffsetIndex": -1,
867+ "_defaultItemSize": 123,
868+ "_gap": 0,
869+ "_length": 10,
870+ "_offsets": [
871+ -1,
872+ -1,
873+ -1,
874+ -1,
875+ -1,
876+ -1,
877+ -1,
878+ -1,
879+ -1,
880+ -1,
881+ ],
882+ "_sizes": [
883+ 0,
884+ 1,
885+ 2,
886+ 3,
887+ 4,
888+ 5,
889+ 6,
890+ 7,
891+ 8,
892+ 9,
893+ ],
894+ }
895+ ` ) ;
887896 expect ( cache . _length ) . toBe ( itemLength ) ;
888897 expect ( cache . _sizes . length ) . toBe ( itemLength ) ;
889898 expect ( cache . _offsets . length ) . toBe ( itemLength ) ;
@@ -926,21 +935,22 @@ describe(takeCacheSnapshot.name, () => {
926935
927936describe ( updateCacheLength . name , ( ) => {
928937 it ( "should recover cache length from 0" , ( ) => {
929- const cache = initCache ( 10 , 40 ) ;
938+ const cache = initCache ( 10 , 40 , 0 ) ;
930939 const initialCache = JSON . parse ( JSON . stringify ( cache ) ) ;
931940 updateCacheLength ( cache , 0 ) ;
932941 updateCacheLength ( cache , 10 ) ;
933942 expect ( cache ) . toEqual ( initialCache ) ;
934943 } ) ;
935944
936945 it ( "should increase cache length" , ( ) => {
937- const cache = initCache ( 10 , 40 ) ;
946+ const cache = initCache ( 10 , 40 , 0 ) ;
938947 const res = updateCacheLength ( cache , 15 , undefined ) ;
939948 expect ( res ) . toEqual ( 40 * 5 ) ;
940949 expect ( cache ) . toMatchInlineSnapshot ( `
941950 {
942951 "_computedOffsetIndex": -1,
943952 "_defaultItemSize": 40,
953+ "_gap": 0,
944954 "_length": 15,
945955 "_offsets": [
946956 -1,
@@ -989,6 +999,7 @@ describe(updateCacheLength.name, () => {
989999 {
9901000 "_computedOffsetIndex": 9,
9911001 "_defaultItemSize": 40,
1002+ "_gap": 0,
9921003 "_length": 15,
9931004 "_offsets": [
9941005 0,
@@ -1029,13 +1040,14 @@ describe(updateCacheLength.name, () => {
10291040 } ) ;
10301041
10311042 it ( "should decrease cache length" , ( ) => {
1032- const cache = initCache ( 10 , 40 ) ;
1043+ const cache = initCache ( 10 , 40 , 0 ) ;
10331044 const res = updateCacheLength ( cache , 5 , undefined ) ;
10341045 expect ( res ) . toEqual ( - ( 40 * 5 ) ) ;
10351046 expect ( cache ) . toMatchInlineSnapshot ( `
10361047 {
10371048 "_computedOffsetIndex": -1,
10381049 "_defaultItemSize": 40,
1050+ "_gap": 0,
10391051 "_length": 5,
10401052 "_offsets": [
10411053 -1,
@@ -1064,6 +1076,7 @@ describe(updateCacheLength.name, () => {
10641076 {
10651077 "_computedOffsetIndex": 4,
10661078 "_defaultItemSize": 40,
1079+ "_gap": 0,
10671080 "_length": 5,
10681081 "_offsets": [
10691082 0,
@@ -1084,13 +1097,14 @@ describe(updateCacheLength.name, () => {
10841097 } ) ;
10851098
10861099 it ( "should increase cache length with shifting" , ( ) => {
1087- const cache = initCache ( 10 , 40 ) ;
1100+ const cache = initCache ( 10 , 40 , 0 ) ;
10881101 const res = updateCacheLength ( cache , 15 , true ) ;
10891102 expect ( res ) . toEqual ( 40 * 5 ) ;
10901103 expect ( cache ) . toMatchInlineSnapshot ( `
10911104 {
10921105 "_computedOffsetIndex": -1,
10931106 "_defaultItemSize": 40,
1107+ "_gap": 0,
10941108 "_length": 15,
10951109 "_offsets": [
10961110 -1,
@@ -1139,6 +1153,7 @@ describe(updateCacheLength.name, () => {
11391153 {
11401154 "_computedOffsetIndex": -1,
11411155 "_defaultItemSize": 40,
1156+ "_gap": 0,
11421157 "_length": 15,
11431158 "_offsets": [
11441159 0,
@@ -1179,13 +1194,14 @@ describe(updateCacheLength.name, () => {
11791194 } ) ;
11801195
11811196 it ( "should decrease cache length with shifting" , ( ) => {
1182- const cache = initCache ( 10 , 40 ) ;
1197+ const cache = initCache ( 10 , 40 , 0 ) ;
11831198 const res = updateCacheLength ( cache , 5 , true ) ;
11841199 expect ( res ) . toEqual ( - ( 40 * 5 ) ) ;
11851200 expect ( cache ) . toMatchInlineSnapshot ( `
11861201 {
11871202 "_computedOffsetIndex": -1,
11881203 "_defaultItemSize": 40,
1204+ "_gap": 0,
11891205 "_length": 5,
11901206 "_offsets": [
11911207 -1,
@@ -1214,6 +1230,7 @@ describe(updateCacheLength.name, () => {
12141230 {
12151231 "_computedOffsetIndex": -1,
12161232 "_defaultItemSize": 40,
1233+ "_gap": 0,
12171234 "_length": 5,
12181235 "_offsets": [
12191236 0,
0 commit comments