33 using System ;
44 using System . Collections ;
55 using System . Collections . Generic ;
6- using System . Diagnostics . Contracts ;
76
87 /// <summary>
98 /// https://en.wikipedia.org/wiki/Circular_buffer
@@ -40,7 +39,9 @@ public CircularBuffer(int capacity)
4039 /// <returns></returns>
4140 public void AddHead ( T item )
4241 {
42+ #if CONTRACTS_FULL
4343 Contract . Requires < ArgumentException > ( this . Count < this . Capacity ) ;
44+ #endif
4445
4546 if ( this . head == - 1 )
4647 {
@@ -63,7 +64,9 @@ public void AddHead(T item)
6364 /// <returns></returns>
6465 public void AddTail ( T item )
6566 {
67+ #if CONTRACTS_FULL
6668 Contract . Assert ( this . Count < this . array . Length ) ;
69+ #endif
6770
6871 if ( this . head == - 1 )
6972 {
@@ -85,7 +88,9 @@ public void AddTail(T item)
8588 /// <param name="items"></param>
8689 public void AddTail ( IEnumerable < T > items )
8790 {
91+ #if CONTRACTS_FULL
8892 Contract . Requires < ArgumentNullException > ( items != null ) ;
93+ #endif
8994
9095 foreach ( var item in items )
9196 {
@@ -99,7 +104,9 @@ public void AddTail(IEnumerable<T> items)
99104 /// <returns></returns>
100105 public T PeekHead ( )
101106 {
107+ #if CONTRACTS_FULL
102108 Contract . Requires < InvalidOperationException > ( this . Count > 0 ) ;
109+ #endif
103110 return this . array [ this . head ] ;
104111 }
105112
@@ -109,7 +116,9 @@ public T PeekHead()
109116 /// <returns></returns>
110117 public T RemoveHead ( )
111118 {
119+ #if CONTRACTS_FULL
112120 Contract . Requires < InvalidOperationException > ( this . Count > 0 ) ;
121+ #endif
113122
114123 var item = this . array [ this . head ] ;
115124 this . array [ this . head ] = default ( T ) ;
@@ -125,7 +134,9 @@ public T RemoveHead()
125134 /// <returns></returns>
126135 public T PeekTail ( )
127136 {
137+ #if CONTRACTS_FULL
128138 Contract . Requires < InvalidOperationException > ( this . Count > 0 ) ;
139+ #endif
129140
130141 return this . array [ this . tail ] ;
131142 }
@@ -136,7 +147,9 @@ public T PeekTail()
136147 /// <returns></returns>
137148 public T RemoveTail ( )
138149 {
150+ #if CONTRACTS_FULL
139151 Contract . Requires < InvalidOperationException > ( this . Count > 0 ) ;
152+ #endif
140153
141154 var item = this . array [ this . tail ] ;
142155 this . array [ this . tail ] = default ( T ) ;
@@ -151,7 +164,9 @@ public T RemoveTail()
151164 /// <param name="capacity"></param>
152165 public void SetCapacity ( int capacity )
153166 {
167+ #if CONTRACTS_FULL
154168 Contract . Requires < InvalidOperationException > ( capacity >= this . Count ) ;
169+ #endif
155170
156171 var target = new T [ capacity ] ;
157172 if ( this . Count > 0 )
@@ -179,7 +194,7 @@ public void SetCapacity(int capacity)
179194 this . array = target ;
180195 }
181196
182- #region IList<T> Members
197+ #region IList<T> Members
183198
184199 int IList < T > . IndexOf ( T item )
185200 {
@@ -216,9 +231,9 @@ public T this[int index]
216231 }
217232 }
218233
219- #endregion
234+ #endregion
220235
221- #region ICollection<T> Members
236+ #region ICollection<T> Members
222237
223238 void ICollection < T > . Add ( T item )
224239 {
@@ -252,9 +267,9 @@ bool ICollection<T>.Remove(T item)
252267 throw new NotImplementedException ( ) ;
253268 }
254269
255- #endregion
270+ #endregion
256271
257- #region IEnumerable<T> Members
272+ #region IEnumerable<T> Members
258273
259274 IEnumerator < T > IEnumerable < T > . GetEnumerator ( )
260275 {
@@ -275,16 +290,16 @@ IEnumerator<T> IEnumerable<T>.GetEnumerator()
275290 }
276291 }
277292
278- #endregion
293+ #endregion
279294
280- #region IEnumerable Members
295+ #region IEnumerable Members
281296
282297 IEnumerator IEnumerable . GetEnumerator ( )
283298 {
284299 var enumerable = ( IEnumerable < T > ) this ;
285300 return enumerable . GetEnumerator ( ) ;
286301 }
287302
288- #endregion
303+ #endregion
289304 }
290305}
0 commit comments