18 using System.Collections.Generic;
24 namespace Deveel.Data.Index {
33 IndexNumber = indexNumber;
34 MaxBlockSize = maxBlockSize;
36 deletedBlocks =
new List<IMappedBlock>();
40 public int IndexNumber {
get;
private set; }
42 public int MaxBlockSize {
get;
private set; }
46 public IEnumerable<IIndexBlock<int>> AllBlocks {
47 get {
return Blocks.ToArray(); }
50 public IEnumerable<IMappedBlock> DeletedBlocks {
51 get {
return deletedBlocks.ToArray(); }
56 throw new ObjectDisposedException(GetType().FullName);
71 GC.SuppressFinalize(
this);
77 if (deletedBlocks != null)
78 deletedBlocks.Clear();
88 int size, byte compactType,
int blockSize) {
89 return new MappedBlock(indexSetStore, firstEntry, lastEntry, blockPointer, size, compactType, blockSize);
97 private object blockLock =
new object();
108 : base(index.MaxBlockSize) {
114 public MappedBlock(
IndexSetStore indexSetStore,
long firstEntry,
long lastEntry,
long blockPointer,
int size, byte compactType,
int maxBlockSize) {
116 FirstEntry = firstEntry;
117 LastEntry = lastEntry;
118 BlockPointer = blockPointer;
119 CompactType = compactType;
121 this.maxBlockSize = maxBlockSize;
126 public long FirstEntry {
get;
private set; }
128 public long LastEntry {
get;
private set; }
130 public long BlockPointer {
get;
private set; }
132 public byte CompactType {
get;
private set; }
134 public override int Top {
137 throw new InvalidOperationException(
"No first int in block.");
140 return BaseArray == null ? (int)LastEntry : BaseArray[Count - 1];
145 public override int Bottom {
148 throw new InvalidOperationException(
"No first int in block.");
151 return BaseArray == null ? (int)FirstEntry : BaseArray[0];
156 protected override int ArrayLength {
157 get {
return maxBlockSize; }
162 if (!readOnly && !mutableBlock) {
163 BaseArray = (
int[])BaseArray.Clone();
170 int entrySize = CompactType;
172 int areaSize = (Count * entrySize);
176 long destOffset = dest.
Id;
177 Store.GetArea(BlockPointer).CopyTo(dest, areaSize);
189 for (
int i = 0; i < Count; ++i) {
190 long v = BaseArray[i];
196 long lv = largestVal;
197 if (lv >> 7 == 0 || lv >> 7 == -1) {
199 }
else if (lv >> 15 == 0 || lv >> 15 == -1) {
201 }
else if (lv >> 23 == 0 || lv >> 23 == -1) {
211 int entrySize = CompactType;
213 int areaSize = (Count * entrySize);
216 byte[] arr =
new byte[areaSize];
219 for (
int i = 0; i < Count; ++i) {
220 int v = BaseArray[i];
221 for (
int n = entrySize - 1; n >= 0; --n) {
229 var a = Store.CreateArea(areaSize);
232 a.Write(arr, 0, areaSize);
245 if (BaseArray != null) {
246 PrepareMutate(readOnly);
251 BaseArray =
new int[maxBlockSize];
254 int entrySize = CompactType;
256 int areaSize = (Count * entrySize);
259 byte[] buf =
new byte[areaSize];
261 Store.GetArea(BlockPointer).Read(buf, 0, areaSize);
262 }
catch (IOException e) {
263 throw new InvalidOperationException(
"IO Error: " + e.Message);
268 for (
int i = 0; i < Count; ++i) {
269 int v = (((int)buf[p]) << ((entrySize - 1) * 8));
271 for (
int n = entrySize - 2; n >= 0; --n) {
272 v = v | ((((int)buf[p]) & 0x0FF) << (n * 8));
278 mutableBlock =
false;
279 PrepareMutate(readOnly);
override IIndexBlock< int > NewBlock()
IArea CreateArea(long size)
Allocates a block of memory in the store of the specified size and returns an IArea object that can b...
MappedBlock(StoreIndex index)
static IMappedBlock NewMappedBlock(IndexSetStore indexSetStore, long firstEntry, long lastEntry, long blockPointer, int size, byte compactType, int blockSize)
override int[] GetArray(bool readOnly)
IndexSetStore IndexSetStore
override void OnDeleteBlock(IIndexBlock< int > block)
void Dispose(bool disposing)
MappedBlock(IndexSetStore indexSetStore, long firstEntry, long lastEntry, long blockPointer, int size, byte compactType, int maxBlockSize)
static int URShift(int number, int bits)
Operates a shift on the given integer by the number of bits specified.
An interface for querying and accessing an index of primitive integers.
A wrapper for an array of byte.
List< IMappedBlock > deletedBlocks
An implementation of BlockIndexBase that stores all values in blocks that are entirely stored in m...
readonly int maxBlockSize
void PrepareMutate(bool readOnly)
long Id
Returns the unique identifier that represents this area.
A store is a resource where areas can be allocated and freed to store information (a memory allocator...
StoreIndex(IndexSetStore indexSetStore, int indexNumber, int maxBlockSize, IEnumerable< IIndexBlock< int >> blocks)
long CopyTo(IStore destStore)