This repository has been archived by the owner on Jun 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
226 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace FileExplorer | ||
{ | ||
public class Cache | ||
{ | ||
public long TotalSize { get; set; } | ||
|
||
public IBigFileHelper FileHelper { get; set; } | ||
|
||
public List<Block> BlockList { get; private set; } | ||
|
||
public Cache() | ||
{ | ||
TotalSize = 0L; | ||
BlockList = new List<Block>(); | ||
} | ||
|
||
public bool Add(long position, byte[] data, int size) | ||
{ | ||
Block block = new Block(); | ||
block.Position = position; | ||
block.Data = data; | ||
block.Size = size; | ||
BlockList.Add(block); | ||
TotalSize += size; | ||
return true; | ||
} | ||
|
||
public bool Flush() | ||
{ | ||
BlockList.Sort(new BlockComparer()); | ||
foreach (Block block in BlockList) | ||
{ | ||
FileHelper.Update(block.Position, block.Data, 0, block.Size); | ||
} | ||
return true; | ||
} | ||
|
||
public bool Reset() | ||
{ | ||
TotalSize = 0; | ||
BlockList.Clear(); | ||
return true; | ||
} | ||
|
||
public class Block | ||
{ | ||
public long Position { get; set; } | ||
|
||
public int Size { get; set; } | ||
|
||
public byte[] Data { get; set; } | ||
} | ||
|
||
public class BlockComparer : IComparer<Block> | ||
{ | ||
public int Compare(Block x, Block y) | ||
{ | ||
long xpos = x == null ? 0L : x.Position; | ||
long ypos = y == null ? 0L : y.Position; | ||
return xpos < ypos ? -1 : (xpos > ypos ? 1 : 0); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.