[Quantproject-developers] QuantProject/b3_Data/DataProviders/Bars/Caching BarCacheData.cs, 1.2, 1.
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2008-12-31 02:25:08
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/Bars/Caching In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv13153/b3_Data/DataProviders/Bars/Caching Modified Files: BarCacheData.cs Log Message: The code has been refactored to be better organized and more readable Index: BarCacheData.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/Bars/Caching/BarCacheData.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** BarCacheData.cs 18 Dec 2008 20:06:27 -0000 1.2 --- BarCacheData.cs 31 Dec 2008 02:24:57 -0000 1.3 *************** *** 27,30 **** --- 27,36 ---- { /// <summary> + /// this event is risen when the cache has reached it max size and it needs to + /// remove some items + /// </summary> + public delegate void CleaningUpEventHandler( object sender ); + + /// <summary> /// Basic data structure used by bar caches: each IBarCache will use its own /// strategy, but it will probably use this class for adding bars to the cache *************** *** 33,36 **** --- 39,44 ---- public class BarCacheData { + public event CleaningUpEventHandler CleaningUp; + private int maxNumberOfItemsIn_bars; private int numberOfItemsToBeRemovedFrom_bars_whenCacheIsCleanedUp; *************** *** 72,86 **** #region AddBar - private void add_dateTime_toCacheIfTheCase( - DateTime dateTime ) - { - if ( !this.bars.ContainsKey( dateTime ) ) - // no data is yet in cache for this dateTime and a - this.bars.Add( dateTime , new Dictionary< string , double >() ); - } ! #region addBar_with_dateTime_alreadyInCache ! ! #region addBar_actually #region removeValuesFromTheCacheIfMaxSizeHasBeenReached --- 80,85 ---- #region AddBar ! #region addNonPresentBar #region removeValuesFromTheCacheIfMaxSizeHasBeenReached *************** *** 133,138 **** #region removeCurrentItemFrom_bars_actually - - #region removeCurrentItemFrom_bars_only private void removeCurrentDateTimeFromCache_ifAllBarsHaveBeenRemovedForThatDateTime( DateTime dateTimeForLastBarRemovedFromCache ) --- 132,135 ---- *************** *** 142,146 **** this.bars.Remove( dateTimeForLastBarRemovedFromCache ); } ! private void removeCurrentItemFrom_bars_only() { DateTime dateTimeForCurrentBarToBeRemoved = --- 139,143 ---- this.bars.Remove( dateTimeForLastBarRemovedFromCache ); } ! private void removeCurrentItemFrom_bars_actually() { DateTime dateTimeForCurrentBarToBeRemoved = *************** *** 153,157 **** dateTimeForCurrentBarToBeRemoved ); } ! #endregion removeCurrentItemFrom_bars_only #region updateMembersUsedToCleanUp_bars --- 150,161 ---- dateTimeForCurrentBarToBeRemoved ); } ! #endregion removeCurrentItemFrom_bars_actually ! ! private void removeCurrentItemFrom_bars() ! { ! removeCurrentItemFrom_bars_actually(); ! this.numberOfBarsIn_bars--; ! } ! #endregion removeCurrentItemFrom_bars #region updateMembersUsedToCleanUp_bars *************** *** 174,191 **** #endregion updateMembersUsedToCleanUp_bars - private void removeCurrentItemFrom_bars_actually() - { - this.removeCurrentItemFrom_bars_only(); - // this.updateMembersUsedToCleanUp_bars(); - } - #endregion removeCurrentItemFrom_bars_actually - - private void removeCurrentItemFrom_bars() - { - removeCurrentItemFrom_bars_actually(); - this.numberOfBarsIn_bars--; - } - #endregion removeCurrentItemFrom_bars - private void removeNextItemFrom_bars() { --- 178,181 ---- *************** *** 215,259 **** if ( this.numberOfBarsIn_bars >= this.maxNumberOfItemsIn_bars ) // the cache is full this.removeValuesFromTheCache(); } #endregion removeValuesFromTheCacheIfMaxSizeHasBeenReached ! private void addBar_actually( ! string ticker, double barOpenValue , ! Dictionary< string , double > barsInDictionaryForTheGivenDateTime ) { ! this.removeValuesFromTheCacheIfMaxSizeHasBeenReached(); ! barsInDictionaryForTheGivenDateTime.Add( ticker , barOpenValue ); ! this.numberOfBarsIn_bars++; } - #endregion addBar_actually ! private void addBar( string ticker, double barOpenValue , Dictionary< string , double > barsInDictionaryForTheGivenDateTime ) { ! if ( !barsInDictionaryForTheGivenDateTime.ContainsKey( ticker ) ) ! // the cache doesn't contain the open value ! // for the given ticker and the given dateTime ! this.addBar_actually( ! ticker , barOpenValue , barsInDictionaryForTheGivenDateTime); } ! // private void addBarOpenValue( ! // Dictionary< string , double > barOpenValuesInCacheForGivenDateTime , ! // string ticker, DateTime dateTime , double theValue ) // { ! // this.addBarOpenValue( ! // barOpenValuesInCacheForGivenDateTime , ticker , barOpenValue ); // } ! private void addBar_with_dateTime_alreadyInCache( string ticker, DateTime dateTime , double theValue ) { Dictionary< string , double > barsInDictionaryForTheGivenDateTime = this.bars[ dateTime ]; ! this.addBar( ticker , theValue , barsInDictionaryForTheGivenDateTime ); } #endregion addBar_with_dateTime_alreadyInCache /// <summary> /// adds a bar to the cache; if there is no more space in the cache, (supposed) --- 205,273 ---- if ( this.numberOfBarsIn_bars >= this.maxNumberOfItemsIn_bars ) // the cache is full + { + if ( this.CleaningUp != null ) + this.CleaningUp( this ); this.removeValuesFromTheCache(); + } } #endregion removeValuesFromTheCacheIfMaxSizeHasBeenReached ! #region addBarWithEnsuredSpaceInTheCache ! private void add_dateTime_toCacheIfTheCase( ! DateTime dateTime ) { ! if ( !this.bars.ContainsKey( dateTime ) ) ! // no data is yet in cache for this dateTime and a ! this.bars.Add( dateTime , new Dictionary< string , double >() ); } ! #region addBar_with_dateTime_alreadyInCache ! ! private void addNonPresentBar_actually( string ticker, double barOpenValue , Dictionary< string , double > barsInDictionaryForTheGivenDateTime ) { ! // this.removeValuesFromTheCacheIfMaxSizeHasBeenReached(); ! barsInDictionaryForTheGivenDateTime.Add( ticker , barOpenValue ); ! this.numberOfBarsIn_bars++; } ! ! // private void addBar( ! // string ticker, double barOpenValue , ! // Dictionary< string , double > barsInDictionaryForTheGivenDateTime ) // { ! // if ( !barsInDictionaryForTheGivenDateTime.ContainsKey( ticker ) ) ! // // the cache doesn't contain the open value ! // // for the given ticker and the given dateTime ! // this.addBar_actually( ! // ticker , barOpenValue , barsInDictionaryForTheGivenDateTime); // } ! private void addNonPresentBar_with_dateTime_alreadyInCache( string ticker, DateTime dateTime , double theValue ) { Dictionary< string , double > barsInDictionaryForTheGivenDateTime = this.bars[ dateTime ]; ! this.addNonPresentBar_actually( ticker , theValue , barsInDictionaryForTheGivenDateTime ); } #endregion addBar_with_dateTime_alreadyInCache + private void addNonPresentBarWithEnsuredSpaceInTheCache( + string ticker, DateTime dateTime , double theValue ) + { + this.add_dateTime_toCacheIfTheCase( dateTime ); + this.addNonPresentBar_with_dateTime_alreadyInCache( + ticker , dateTime , theValue ); + } + #endregion addBarWithEnsuredSpaceInTheCache + + private void addNonPresentBar( + string ticker, DateTime dateTime , double theValue ) + { + this.removeValuesFromTheCacheIfMaxSizeHasBeenReached(); + this.addNonPresentBarWithEnsuredSpaceInTheCache( ticker , dateTime , theValue ); + } + #endregion addNonPresentBar + /// <summary> /// adds a bar to the cache; if there is no more space in the cache, (supposed) *************** *** 266,272 **** string ticker, DateTime dateTime , double theValue ) { ! this.add_dateTime_toCacheIfTheCase( dateTime ); ! this.addBar_with_dateTime_alreadyInCache( ! ticker , dateTime , theValue ); } #endregion AddBar --- 280,285 ---- string ticker, DateTime dateTime , double theValue ) { ! if ( !this.ContainsBar( ticker , dateTime ) ) ! this.addNonPresentBar( ticker , dateTime , theValue ); } #endregion AddBar |