private int SizeOfCodedToken(ClrCodedToken token) { CCodedTokenDef def = MetaModel.g_CodedTokens[(int)token]; int tagSize = CountBits(def.m_pTokens.Length - 1); foreach (var tableMdt in def.m_pTokens) { ClrTable table = tableMdt.GetTable(); int rowIdxSize = CountBits(Math.Max(m_Schema.RowCount[table], 1) - 1); if (tagSize + rowIdxSize > 16) { // one of the possible tables needs the 4 byte token. return(4); } } // we can index all possible tables with a 2-byte token. return(2); }
private int ColumnTypeSize(int type) { if (0 <= type && type <= MetaModel.iRidMax) { ClrTable table = (ClrTable)type; long rowCount = m_Schema.RowCount[table]; return((rowCount > 0xFFFF) ? 4 : 2); } else if (MetaModel.iCodedToken <= type && type <= MetaModel.iCodedTokenMax) { ClrCodedToken cdtkn = (ClrCodedToken)(type - MetaModel.iCodedToken); return(SizeOfCodedToken(cdtkn)); } else if (type == MetaModel.iBYTE) { return(1); } else if (type == MetaModel.iSHORT || type == MetaModel.iUSHORT) { return(2); } else if (type == MetaModel.iLONG || type == MetaModel.iULONG) { return(4); } else if (type == MetaModel.iSTRING) { return(m_Schema.StringIndexSize); } else if (type == MetaModel.iGUID) { return(m_Schema.GuidIndexSize); } else if (type == MetaModel.iBLOB) { return(m_Schema.BlobIndexSize); } throw new ArgumentException("Unexpected metadata field type."); }