Skip to content

Commit 25075eb

Browse files
Added experemental mass skip logic to move forward and backward. This means that you can add a million new rows anyware in the middle and performance hardly changes.
I have NOT updated nuget with this feature yet.. This is a precursor to adding the VirtualTreeCollection.
1 parent 9464029 commit 25075eb

11 files changed

Lines changed: 104 additions & 24 deletions

AlphaChiTech.Virtualization/AlphaChiTech.Virtualization.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<DebugType>full</DebugType>
2626
<Optimize>false</Optimize>
2727
<OutputPath>bin\Debug\</OutputPath>
28-
<DefineConstants>DEBUG;TRACE</DefineConstants>
28+
<DefineConstants>TRACE;DEBUG;EXPEREMENTAL</DefineConstants>
2929
<ErrorReport>prompt</ErrorReport>
3030
<WarningLevel>4</WarningLevel>
3131
</PropertyGroup>

AlphaChiTech.Virtualization/PaginationManager.cs

Lines changed: 101 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -487,45 +487,125 @@ protected void CalculateFromIndex(int index, out int page, out int inneroffset)
487487
private void DoStepBackwards(ref int page, ref int offset, int stepAmount)
488488
{
489489
bool done = false;
490+
int ignoreSteps = -1;
490491

491492
while(!done)
492493
{
493-
int items = this.PageSize;
494-
if (_Deltas.ContainsKey(page)) items += _Deltas[page].Delta;
495-
if(offset - stepAmount < 0)
494+
495+
#if EXPEREMENTAL
496+
if(stepAmount>this.PageSize * 10 && ignoreSteps<=0)
496497
{
497-
stepAmount -= (offset+1);
498-
page--;
499-
items = this.PageSize;
500-
if (_Deltas.ContainsKey(page)) items += _Deltas[page].Delta;
501-
offset = items-1;
502-
}
503-
else
498+
int targetPage = page - stepAmount/this.PageSize;
499+
int sourcePage = page;
500+
var adj = (from a in _Deltas.Values where a.Page >= targetPage && a.Page <= sourcePage orderby a.Page select a);
501+
if(adj.Count() == 0)
502+
{
503+
page = targetPage;
504+
stepAmount -= (sourcePage - targetPage) * this.PageSize;
505+
506+
if(stepAmount == 0)
507+
{
508+
done = true;
509+
}
510+
} else if(adj.Last().Page < page-2)
511+
{
512+
targetPage = adj.Last().Page + 1;
513+
page = targetPage;
514+
stepAmount -= (sourcePage - targetPage) * this.PageSize;
515+
516+
if (stepAmount == 0)
517+
{
518+
done = true;
519+
}
520+
}
521+
else
522+
{
523+
ignoreSteps = sourcePage - adj.Last().Page;
524+
}
525+
}
526+
#endif
527+
528+
if (!done)
504529
{
505-
offset -= stepAmount;
506-
done = true;
530+
int items = this.PageSize;
531+
if (_Deltas.ContainsKey(page)) items += _Deltas[page].Delta;
532+
if (offset - stepAmount < 0)
533+
{
534+
stepAmount -= (offset + 1);
535+
page--;
536+
items = this.PageSize;
537+
if (_Deltas.ContainsKey(page)) items += _Deltas[page].Delta;
538+
offset = items - 1;
539+
}
540+
else
541+
{
542+
offset -= stepAmount;
543+
done = true;
544+
}
545+
546+
ignoreSteps--;
507547
}
508548
}
509549
}
510550

511551
private void DoStepForward(ref int page, ref int offset, int stepAmount)
512552
{
513553
bool done = false;
554+
int ignoreSteps = -1;
514555

515556
while(!done)
516557
{
517-
int items = this.PageSize;
518-
if (_Deltas.ContainsKey(page)) items += _Deltas[page].Delta;
519-
if(items<=offset+stepAmount)
558+
559+
#if EXPEREMENTAL
560+
if (stepAmount > this.PageSize * 10 && ignoreSteps<=0)
520561
{
521-
stepAmount -= (items)-offset;
522-
offset = 0;
523-
page++;
562+
int targetPage = page + stepAmount / this.PageSize;
563+
int sourcePage = page;
564+
var adj = (from a in _Deltas.Values where a.Page <= targetPage && a.Page >= sourcePage orderby a.Page select a);
565+
if (adj.Count() == 0)
566+
{
567+
page = targetPage;
568+
stepAmount -= (targetPage - sourcePage) * this.PageSize;
569+
570+
if (stepAmount == 0)
571+
{
572+
done = true;
573+
}
574+
}
575+
else if (adj.Last().Page > page - 2)
576+
{
577+
targetPage = adj.Last().Page - 1;
578+
page = targetPage;
579+
stepAmount -= (targetPage - sourcePage) * this.PageSize;
580+
581+
if (stepAmount == 0)
582+
{
583+
done = true;
584+
}
585+
} else
586+
{
587+
ignoreSteps = adj.Last().Page - sourcePage;
588+
}
524589
}
525-
else
590+
#endif
591+
592+
if (!done)
526593
{
527-
offset += stepAmount;
528-
done = true;
594+
int items = this.PageSize;
595+
if (_Deltas.ContainsKey(page)) items += _Deltas[page].Delta;
596+
if (items <= offset + stepAmount)
597+
{
598+
stepAmount -= (items) - offset;
599+
offset = 0;
600+
page++;
601+
}
602+
else
603+
{
604+
offset += stepAmount;
605+
done = true;
606+
}
607+
608+
ignoreSteps--;
529609
}
530610
}
531611
}

AlphaChiTech.Virtualization/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@
2626
// You can specify all the values or you can default the Build and Revision Numbers
2727
// by using the '*' as shown below:
2828
// [assembly: AssemblyVersion("1.0.*")]
29-
[assembly: AssemblyVersion("1.0.2.0")]
30-
[assembly: AssemblyFileVersion("1.0.2.0")]
29+
[assembly: AssemblyVersion("1.1.0.0")]
30+
[assembly: AssemblyFileVersion("1.1.0.0")]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)