public List <int> FindPagedRows(string filter, int page, int pageSize, int skip, out int total) { var result = new List <int>(); while (_internalOP) { Thread.Sleep(50); } WAHBitArray bits = ExecutionPlan(filter); var indexes = bits.GetBitIndexes().ToList(); total = indexes.Count; int currentPos = 0, pageStartPos = page * pageSize + (skip > 0 ? skip : 0), pageEndPos = pageStartPos + pageSize; bool isPageable = pageStartPos < pageEndPos; if (!isPageable) { return(indexes); } foreach (int i in indexes) { currentPos++; if (currentPos <= pageStartPos || currentPos > pageEndPos) { continue; } result.Add(i); if (result.Count == pageSize) { break; } } return(result); }
public void TestWAHBitArray3() { var b = new WAHBitArray(); int count = 25; for (int i = 0; i < 5; i++) { b.Set(i, false); } for (int i = 5; i < count + 5; i++) { b.Set(i, true); } for (int i = 30; i < 64; i++) { b.Set(i, i == 35); } for (int i = 64; i < 65; i++) { b.Set(i, true); } var expected = b.GetBitIndexes().ToArray(); var b2 = new WAHBitArray(WAHBitArray.TYPE.Compressed_WAH, b.GetCompressed()); var actual = b2.GetBitIndexes().ToArray(); expected.Should(Be.EqualTo(actual), "expected.Should(Be.EqualTo(actual))"); }
public List <TDocument> FindPagedDocuments <TDocument>(WAHBitArray plan, int page, int pageSize, int skip, out int total) where TDocument : Document { var result = new List <TDocument>(); int pageStartPos = page * pageSize + (skip > 0 ? skip : 0), pageEndPos = pageStartPos + pageSize; int[] indexes = plan.GetBitIndexes().ToArray(); total = indexes.Length; for (int k = total - pageStartPos - 1; k > total - pageEndPos - 1; k--) { if (k < 0) { break; } var index = indexes[k]; if (index > _lastDocNum - 1) { continue; } byte[] b = _docs.ReadData(index); var d = JSON.Instance.ToObject <TDocument>(Helper.GetString(b)); result.Add(d); } return(result); }
public void TestWAHBitArray1() { var b = new WAHBitArray(); int count = 31; for (int i = 0; i < count; i++) { b.Set(i, true); } var expected = b.GetBitIndexes().ToArray(); var b2 = new WAHBitArray(WAHBitArray.TYPE.Compressed_WAH, b.GetCompressed()); var actual = b2.GetBitIndexes().ToArray(); expected.Should(Be.EqualTo(actual), "expected.Should(Be.EqualTo(actual))"); }