public virtual void TestLru() { LRUHashMap<string, string> lru = new LRUHashMap<string, string>(3); Assert.AreEqual(0, lru.Size()); lru.Put("one", "Hello world"); Assert.AreEqual(1, lru.Size()); lru.Put("two", "Hi man"); Assert.AreEqual(2, lru.Size()); lru.Put("three", "Bonjour"); Assert.AreEqual(3, lru.Size()); lru.Put("four", "Shalom"); Assert.AreEqual(3, lru.Size()); Assert.NotNull(lru.Get("three")); Assert.NotNull(lru.Get("two")); Assert.NotNull(lru.Get("four")); Assert.Null(lru.Get("one")); lru.Put("five", "Yo!"); Assert.AreEqual(3, lru.Size()); Assert.Null(lru.Get("three")); // three was last used, so it got removed Assert.NotNull(lru.Get("five")); lru.Get("four"); lru.Put("six", "hi"); lru.Put("seven", "hey dude"); Assert.AreEqual(3, lru.Size()); Assert.Null(lru.Get("one")); Assert.Null(lru.Get("two")); Assert.Null(lru.Get("three")); Assert.NotNull(lru.Get("four")); Assert.Null(lru.Get("five")); Assert.NotNull(lru.Get("six")); Assert.NotNull(lru.Get("seven")); }
protected internal override void DoClose() { indexReader.Dispose(); taxoArrays = null; // do not clear() the caches, as they may be used by other DTR instances. ordinalCache = null; categoryCache = null; }
/// <summary> /// Called only from <seealso cref="#doOpenIfChanged()"/>. If the taxonomy has been /// recreated, you should pass {@code null} as the caches and parent/children /// arrays. /// </summary> internal DirectoryTaxonomyReader(DirectoryReader indexReader, DirectoryTaxonomyWriter taxoWriter, LRUHashMap<FacetLabel, IntClass> ordinalCache, LRUHashMap<int, FacetLabel> categoryCache, TaxonomyIndexArrays taxoArrays) { this.indexReader = indexReader; this.taxoWriter = taxoWriter; this.taxoEpoch = taxoWriter == null ? -1 : taxoWriter.TaxonomyEpoch; // use the same instance of the cache, note the protective code in getOrdinal and getPath this.ordinalCache = ordinalCache == null ? new LRUHashMap<FacetLabel, IntClass>(DEFAULT_CACHE_VALUE) : ordinalCache; this.categoryCache = categoryCache == null ? new LRUHashMap<int, FacetLabel>(DEFAULT_CACHE_VALUE) : categoryCache; this.taxoArrays = taxoArrays != null ? new TaxonomyIndexArrays(indexReader, taxoArrays) : null; }
/// <summary> /// Open for reading a taxonomy stored in a given <seealso cref="Directory"/>. /// </summary> /// <param name="directory"> /// The <seealso cref="Directory"/> in which the taxonomy resides. </param> /// <exception cref="CorruptIndexException"> /// if the Taxonomy is corrupt. </exception> /// <exception cref="IOException"> /// if another error occurred. </exception> public DirectoryTaxonomyReader(Directory directory) { indexReader = OpenIndexReader(directory); taxoWriter = null; taxoEpoch = -1; // These are the default cache sizes; they can be configured after // construction with the cache's setMaxSize() method ordinalCache = new LRUHashMap <FacetLabel, IntClass>(DEFAULT_CACHE_VALUE); categoryCache = new LRUHashMap <int, FacetLabel>(DEFAULT_CACHE_VALUE); }
/// <summary> /// Called only from <seealso cref="#doOpenIfChanged()"/>. If the taxonomy has been /// recreated, you should pass {@code null} as the caches and parent/children /// arrays. /// </summary> internal DirectoryTaxonomyReader(DirectoryReader indexReader, DirectoryTaxonomyWriter taxoWriter, LRUHashMap <FacetLabel, IntClass> ordinalCache, LRUHashMap <int, FacetLabel> categoryCache, TaxonomyIndexArrays taxoArrays) { this.indexReader = indexReader; this.taxoWriter = taxoWriter; this.taxoEpoch = taxoWriter == null ? -1 : taxoWriter.TaxonomyEpoch; // use the same instance of the cache, note the protective code in getOrdinal and getPath this.ordinalCache = ordinalCache == null ? new LRUHashMap <FacetLabel, IntClass>(DEFAULT_CACHE_VALUE) : ordinalCache; this.categoryCache = categoryCache == null ? new LRUHashMap <int, FacetLabel>(DEFAULT_CACHE_VALUE) : categoryCache; this.taxoArrays = taxoArrays != null ? new TaxonomyIndexArrays(indexReader, taxoArrays) : null; }
/// <summary> /// Opens a <seealso cref="DirectoryTaxonomyReader"/> over the given /// <seealso cref="DirectoryTaxonomyWriter"/> (for NRT). /// </summary> /// <param name="taxoWriter"> /// The <seealso cref="DirectoryTaxonomyWriter"/> from which to obtain newly /// added categories, in real-time. </param> public DirectoryTaxonomyReader(DirectoryTaxonomyWriter taxoWriter) { this.taxoWriter = taxoWriter; taxoEpoch = taxoWriter.TaxonomyEpoch; indexReader = OpenIndexReader(taxoWriter.InternalIndexWriter); // These are the default cache sizes; they can be configured after // construction with the cache's setMaxSize() method ordinalCache = new LRUHashMap <FacetLabel, IntClass>(DEFAULT_CACHE_VALUE); categoryCache = new LRUHashMap <int, FacetLabel>(DEFAULT_CACHE_VALUE); }
/// <summary> /// Open for reading a taxonomy stored in a given <seealso cref="Directory"/>. /// </summary> /// <param name="directory"> /// The <seealso cref="Directory"/> in which the taxonomy resides. </param> /// <exception cref="CorruptIndexException"> /// if the Taxonomy is corrupt. </exception> /// <exception cref="IOException"> /// if another error occurred. </exception> public DirectoryTaxonomyReader(Directory directory) { indexReader = OpenIndexReader(directory); taxoWriter = null; taxoEpoch = -1; // These are the default cache sizes; they can be configured after // construction with the cache's setMaxSize() method ordinalCache = new LRUHashMap<FacetLabel, IntClass>(DEFAULT_CACHE_VALUE); categoryCache = new LRUHashMap<int, FacetLabel>(DEFAULT_CACHE_VALUE); }
/// <summary> /// Opens a <seealso cref="DirectoryTaxonomyReader"/> over the given /// <seealso cref="DirectoryTaxonomyWriter"/> (for NRT). /// </summary> /// <param name="taxoWriter"> /// The <seealso cref="DirectoryTaxonomyWriter"/> from which to obtain newly /// added categories, in real-time. </param> public DirectoryTaxonomyReader(DirectoryTaxonomyWriter taxoWriter) { this.taxoWriter = taxoWriter; taxoEpoch = taxoWriter.TaxonomyEpoch; indexReader = OpenIndexReader(taxoWriter.InternalIndexWriter); // These are the default cache sizes; they can be configured after // construction with the cache's setMaxSize() method ordinalCache = new LRUHashMap<FacetLabel, IntClass>(DEFAULT_CACHE_VALUE); categoryCache = new LRUHashMap<int, FacetLabel>(DEFAULT_CACHE_VALUE); }