public void FindDoubledValueTest() { DoubleHashtable table = new DoubleHashtable(); table.Insert(1, "555"); table.Insert(2, "555"); table.Insert(1, "666"); Assert.AreEqual(table.Search(1), "555"); }
public void FindAddedValueTest(int[] keys, string[] values, int keyToFind, string expectedResult) { DoubleHashtable table = new DoubleHashtable(); for (int i = 0; i < keys.Length; i++) { table.Insert(keys[i], values[i]); } Assert.AreEqual(table.Search(keyToFind), expectedResult); }
public void DeleteDoubledValueTest() { DoubleHashtable table = new DoubleHashtable(); table.Insert(1, "555"); table.Insert(2, "555"); table.Insert(1, "666"); table.Delete(1); Assert.IsNull(table.Search(1)); }
public void DeleteValueTest(int[] keys, string[] values, int keyToDelete) { DoubleHashtable table = new DoubleHashtable(); for (int i = 0; i < keys.Length; i++) { table.Insert(keys[i], values[i]); } table.Delete(keyToDelete); Assert.IsNull(table.Search(keyToDelete)); }
uint GetFieldReferenceInternedId(IFieldReference fieldReference) { Contract.Requires(fieldReference != null); uint containingTypeReferenceInternedId = this.GetTypeReferenceInternId(fieldReference.ContainingType); uint fieldTypeInternedId; if (fieldReference.IsModified) fieldTypeInternedId = this.GetModifiedTypeReferenceInternId(fieldReference.Type, fieldReference.CustomModifiers); else fieldTypeInternedId = this.GetTypeReferenceInternId(fieldReference.Type); uint fieldNameId = (uint)fieldReference.Name.UniqueKey; var fieldsForType = this.FieldReferenceHashtable.Find(containingTypeReferenceInternedId); if (fieldsForType == null) { fieldsForType = new DoubleHashtable(); this.FieldReferenceHashtable.Add(containingTypeReferenceInternedId, fieldsForType); } uint result = fieldsForType.Find(fieldNameId, fieldTypeInternedId); if (result == 0) { result = this.CurrentFieldReferenceInternValue++; fieldsForType.Add(fieldNameId, fieldTypeInternedId, result); } return result; }
/// <summary> /// /// </summary> public InternFactory() { this.CurrentAssemblyInternValue = 0x00001000; this.CurrentMethodReference = Dummy.MethodReference; this.CurrentModuleInternValue = 0x00000001; this.CurrentNamespaceInternValue = 0x00000001; this.CurrentTypeInternValue = 0x00000100; this.CurrentTypeListInternValue = 0x00000001; this.CurrentCustomModifierInternValue = 0x00000001; this.CurrentCustomModifierListInternValue = 0x00000001; this.CurrentMethodReferenceInternValue = 0x00000001; this.CurrentFieldReferenceInternValue = 0x00000001; this.CurrentParameterTypeInternValue = 0x00000001; this.CurrentParameterTypeListInternValue = 0x00000001; this.CurrentSignatureInternValue = 0x00000001; this.AssemblyHashtable = new MultiHashtable<AssemblyStore>(); this.ModuleHashtable = new MultiHashtable<ModuleStore>(); this.NestedNamespaceHashtable = new DoubleHashtable(); this.NamespaceTypeHashtable = new MultiHashtable<NamespaceTypeStore>(); this.NestedTypeHashtable = new MultiHashtable<NestedTypeStore>(); this.VectorTypeHashTable = new Hashtable(); this.PointerTypeHashTable = new Hashtable(); this.ManagedPointerTypeHashTable = new Hashtable(); this.MatrixTypeHashtable = new MultiHashtable<MatrixTypeStore>(); this.TypeListHashtable = new DoubleHashtable(); this.GenericTypeInstanceHashtable = new DoubleHashtable(); this.GenericMethodInstanceHashtable = new DoubleHashtable(); this.GenericTypeParameterHashtable = new DoubleHashtable(); this.GenericMethodTypeParameterHashTable = new DoubleHashtable(); this.CustomModifierHashTable = new DoubleHashtable(); this.CustomModifierListHashTable = new DoubleHashtable(); this.ParameterTypeHashtable = new MultiHashtable<ParameterTypeStore>(); this.ParameterTypeListHashtable = new DoubleHashtable(); this.SignatureHashtable = new MultiHashtable<SignatureStore>(); this.FunctionTypeHashTable = new Hashtable(); this.ModifiedTypeHashtable = new DoubleHashtable(); this.MethodReferenceHashtable = new Hashtable<MultiHashtable<SignatureStore>>(); this.FieldReferenceHashtable = new Hashtable<DoubleHashtable>(); }
//^ requires peFileReader.IsAssembly ==> moduleIdentity.ContainingAssembly != null; //^ requires peFileReader.IsAssembly ==> containingAssembly == null; //^ requires !(moduleIdentity.Location != null && moduleIdentity.Location.Length != 0); /*^ #pragma warning disable 2666, 2669, 2677, 2674 ^*/ internal PEFileToObjectModel( PeReader peReader, PEFileReader peFileReader, ModuleIdentity moduleIdentity, Assembly/*?*/ containingAssembly, byte pointerSize ) { this.pointerSize = pointerSize; this.ModuleReader = peReader; this.PEFileReader = peFileReader; this.NameTable = peReader.metadataReaderHost.NameTable; this.InternFactory = peReader.metadataReaderHost.InternFactory; this.StringIndexToNameTable = new Hashtable<IName>(); this.StringIndexToUnmangledNameTable = new Hashtable<IName>(); this.typeCache = new TypeCache(this); uint moduleNameOffset = peFileReader.ModuleTable.GetName(1); IName moduleName = this.GetNameFromOffset(moduleNameOffset); AssemblyIdentity/*?*/ assemblyIdentity = moduleIdentity as AssemblyIdentity; if (peFileReader.IsAssembly) { //^ assert assemblyIdentity != null; AssemblyRow assemblyRow = peFileReader.AssemblyTable[1]; IName assemblyName = this.GetNameFromOffset(assemblyRow.Name); byte[] publicKeyArray = TypeCache.EmptyByteArray; if (assemblyRow.PublicKey != 0) { publicKeyArray = peFileReader.BlobStream[assemblyRow.PublicKey]; } uint internedModuleId = (uint)peReader.metadataReaderHost.InternFactory.GetAssemblyInternedKey(assemblyIdentity); Assembly assem = new Assembly(this, moduleName, peFileReader.COR20Header.COR20Flags, internedModuleId, assemblyIdentity, assemblyName, assemblyRow.Flags, publicKeyArray); this.ContainingAssembly = assem; this.Module = assem; } else { uint internedModuleId = (uint)peReader.metadataReaderHost.InternFactory.GetModuleInternedKey(moduleIdentity); this.ContainingAssembly = containingAssembly; this.Module = new Module(this, moduleName, peFileReader.COR20Header.COR20Flags, internedModuleId, moduleIdentity); } this.LoadAssemblyReferences(); this.LoadModuleReferences(); this.RootModuleNamespace = new RootNamespace(this); this.NamespaceINameHashtable = new Hashtable<Namespace>(); this.LoadNamespaces(); this.NamespaceReferenceINameHashtable = new DoubleHashtable<NamespaceReference>(); this.NamespaceTypeTokenTable = new DoubleHashtable(peFileReader.TypeDefTable.NumberOfRows + peFileReader.ExportedTypeTable.NumberOfRows); this.NestedTypeTokenTable = new DoubleHashtable(peFileReader.NestedClassTable.NumberOfRows + peFileReader.ExportedTypeTable.NumberOfRows); this.PreLoadTypeDefTableLookup(); this.ModuleTypeDefArray = new TypeBase/*?*/[peFileReader.TypeDefTable.NumberOfRows + 1]; this.ModuleTypeDefLoadState = new LoadState[peFileReader.TypeDefTable.NumberOfRows + 1]; this.ModuleTypeDefLoadState[0] = LoadState.Loaded; this.ExportedTypeArray = new ExportedTypeAliasBase/*?*/[peFileReader.ExportedTypeTable.NumberOfRows + 1]; this.ExportedTypeLoadState = new LoadState[peFileReader.ExportedTypeTable.NumberOfRows + 1]; this.ExportedTypeLoadState[0] = LoadState.Loaded; this.ModuleGenericParamArray = new GenericParameter[peFileReader.GenericParamTable.NumberOfRows + 1]; if (peFileReader.MethodSpecTable.NumberOfRows > 0) { this.ModuleMethodSpecHashtable = new DoubleHashtable<IGenericMethodInstanceReference>(peFileReader.MethodSpecTable.NumberOfRows + 1); } this.ModuleTypeRefReferenceArray = new IMetadataReaderNamedTypeReference[peFileReader.TypeRefTable.NumberOfRows + 1]; this.ModuleTypeRefReferenceLoadState = new LoadState[peFileReader.TypeRefTable.NumberOfRows + 1]; this.ModuleTypeRefReferenceLoadState[0] = LoadState.Loaded; if (peFileReader.TypeSpecTable.NumberOfRows > 0) { this.ModuleTypeSpecHashtable = new DoubleHashtable<TypeSpecReference>(peFileReader.TypeSpecTable.NumberOfRows + 1); } this.ModuleFieldArray = new FieldDefinition[peFileReader.FieldTable.NumberOfRows + 1]; this.ModuleMethodArray = new IMethodDefinition[peFileReader.MethodTable.NumberOfRows + 1]; this.ModuleEventArray = new EventDefinition[peFileReader.EventTable.NumberOfRows + 1]; this.ModulePropertyArray = new PropertyDefinition[peFileReader.PropertyTable.NumberOfRows + 1]; this.ModuleMemberReferenceArray = new MemberReference/*?*/[peFileReader.MemberRefTable.NumberOfRows + 1]; this.CustomAttributeArray = new ICustomAttribute/*?*/[peFileReader.CustomAttributeTable.NumberOfRows + 1]; this.DeclSecurityArray = new ISecurityAttribute/*?*/[peFileReader.DeclSecurityTable.NumberOfRows + 1]; this._Module_ = this.Create_Module_Type(); }