2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 namespace Mono.Lucene.Net.Util
23 /// <summary> An average, best guess, MemoryModel that should work okay on most systems.
26 public class AverageGuessMemoryModel:MemoryModel
28 public AverageGuessMemoryModel()
32 internal class AnonymousClassIdentityHashMap : System.Collections.Hashtable /*IdentityHashMap*/ // {{Aroush-2.9.0}} Port issue? Will this do the trick to mimic java's IdentityHashMap?
34 public AnonymousClassIdentityHashMap(AverageGuessMemoryModel enclosingInstance)
36 InitBlock(enclosingInstance);
38 private void InitBlock(AverageGuessMemoryModel enclosingInstance)
40 this.enclosingInstance = enclosingInstance;
43 Add(typeof(sbyte), 1);
45 Add(typeof(short), 2);
47 Add(typeof(float), 4);
48 Add(typeof(double), 8);
51 private AverageGuessMemoryModel enclosingInstance;
52 public AverageGuessMemoryModel Enclosing_Instance
56 return enclosingInstance;
60 // {{Aroush-2.9.0}} Port issue? Will this do the trick to mimic java's IdentityHashMap?
63 * This class implements the Map interface with a hash table, using
64 * reference-equality in place of object-equality when comparing keys
65 * (and values). In other words, in an IdentityHashMap, two keys k1 and k2
66 * are considered equal if and only if (k1==k2). (In normal Map
67 * implementations (like HashMap) two keys k1 and k2 are considered
68 * equal if and only if (k1==null ? k2==null : k1.equals(k2)).)
70 public new bool Equals(Object obj)
72 return this.GetHashCode() == obj.GetHashCode();
74 public new static bool Equals(Object objA, Object objB)
76 return objA.GetHashCode() == objB.GetHashCode();
78 // {{Aroush-2.9.0}} Port issue, need to mimic java's IdentityHashMap
80 private void InitBlock()
82 sizes = new AnonymousClassIdentityHashMap(this);
84 // best guess primitive sizes
85 private System.Collections.IDictionary sizes;
90 * @see Mono.Lucene.Net.Util.MemoryModel#getArraySize()
92 public override int GetArraySize()
100 * @see Mono.Lucene.Net.Util.MemoryModel#getClassSize()
102 public override int GetClassSize()
108 * @see Mono.Lucene.Net.Util.MemoryModel#getPrimitiveSize(java.lang.Class)
110 public override int GetPrimitiveSize(System.Type clazz)
112 return ((System.Int32) sizes[clazz]);
116 * @see Mono.Lucene.Net.Util.MemoryModel#getReferenceSize()
118 public override int GetReferenceSize()