Ejemplo n.º 1
0
		public static IndexTable FromCollection(ICollection<object> items)
		{
			var result = new IndexTable ();
			result.entries = new List<object> ();

			if (items.Count <= byte.MaxValue)
				result.type = Type.Tiny;
			else if (items.Count <= UInt16.MaxValue)
				result.type = Type.Small;
			else
				result.type = Type.Normal;

			foreach (var value in items)
				result.entries.Add (value);

			return result;
		}
Ejemplo n.º 2
0
		public static IndexTable[] FromCollection(ICollection<object> items, int maxSplit)
		{
			if (items.Count == 0)
				return null;

			int bucketCount = (int)Math.Ceiling(items.Count / (float)byte.MaxValue);

			if (bucketCount == 1 || bucketCount > maxSplit)
				return new IndexTable[] { FromCollection (items) };

			var keyList = new List<object>(items);
			var result = new IndexTable[bucketCount];

			for (int i = 0, k = 0; i < keyList.Count; i += byte.MaxValue, k++) {
				int end = i + byte.MaxValue;
				int count = Math.Min(end, keyList.Count) - i;

				result[k] = FromCollection(keyList.GetRange(i, count));
			}

			return result;
		}
Ejemplo n.º 3
0
		private void EncodeIndexTable(IndexTable table)
		{
			int count = table.entries.Count;

			if (count <= byte.MaxValue) {
				mWriter.Write ((byte)IndexTable.Type.Tiny);
				mWriter.Write((byte) count);
			} else if (count <= UInt16.MaxValue) {
				mWriter.Write ((byte)IndexTable.Type.Small);
				mWriter.Write((UInt16) count);
			} else {
				mWriter.Write ((byte)IndexTable.Type.Normal);
				mWriter.Write((UInt32) count);
			}

			foreach (var value in table.entries) {
				EncodeElement (value, false);
			}
		}
Ejemplo n.º 4
0
		private IndexTable ReadIndexTable()
		{
			uint count;
			var indexType = (IndexTable.Type)mReader.ReadByte ();

			switch (indexType) {
			case IndexTable.Type.Tiny:
				count = mReader.ReadByte();
				break;
			case IndexTable.Type.Small:
				count = mReader.ReadUInt16();
				break;
			case IndexTable.Type.Normal:
				count = mReader.ReadUInt32();
				break;
			default:
				throw new Exception("Invalid index table type found");
			}

			var table = new IndexTable ();
			table.type = indexType;
			table.entries = new List<object>();

			for (ulong i = 0; i < count; i++)
				table.entries.Add(DecodeElement()); // XXX: do not consider nested elements

			return table;
		}