/// <summary> /// Tries to get the item associated with the specified index from the cached and, if it's not found, reads it through /// <see cref="ReadItem" /> and caches it. /// </summary> /// <param name="index">The item's index.</param> /// <returns>The read item.</returns> public TItem this[DataCenterIndex index] { get { if (cachedItems.TryGetValue(index, out var value)) { return(value); } var valueAddress = GetAddress(index); return(cachedItems[index] = ReadItem(valueAddress)); } }
/// <summary> /// When overridden in a derived class, retrieves the absolute address of an item given its index. /// </summary> /// <param name="regionIndex">The item's index.</param> /// <returns>The item's address.</returns> public abstract int GetAddress(DataCenterIndex regionIndex);
/// <summary> /// Gets the address of the first character of the string at the specified index. /// </summary> /// <param name="regionIndex">The index of the first character of the string.</param> /// <returns>The address of the first character of the string.</returns> public override int GetAddress(DataCenterIndex regionIndex) { return(Characters.GetAddress(regionIndex)); }
/// <summary> /// Gets the address of an item given its index. /// </summary> /// <param name="regionIndex">The item's index.</param> /// <returns>The item's address.</returns> public override int GetAddress(DataCenterIndex regionIndex) { var bucket = Buckets[regionIndex.BucketIndex]; return((int)bucket.FirstValueAddress + regionIndex.ItemIndex * bucket.ValueSize); }