Changeset 14908 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data
- Timestamp:
- 05/02/17 22:03:01 (8 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/List/SkipList.cs
r14875 r14908 50 50 51 51 public SkipListNode(T value) { 52 this.Value = value;52 Value = value; 53 53 } 54 54 … … 62 62 63 63 public virtual bool IsHeader() { 64 return this.GetType() == typeof(SkipListNodeHeader<T>);64 return GetType() == typeof(SkipListNodeHeader<T>); 65 65 } 66 66 67 67 public virtual bool IsFooter() { 68 return this.GetType() == typeof(SkipListNodeFooter<T>);68 return GetType() == typeof(SkipListNodeFooter<T>); 69 69 } 70 70 } … … 162 162 /// </summary> 163 163 protected void clearEmptyLevels() { 164 if ( this.levels > 1) //more than one level, don't want to remove bottom level164 if (levels > 1) //more than one level, don't want to remove bottom level 165 165 { 166 SkipListNode<T> currentNode = t his.topLeft;167 168 while (currentNode != this.bottomLeft) //do not remove the bottom level166 SkipListNode<T> currentNode = topLeft; 167 168 while (currentNode != bottomLeft) //do not remove the bottom level 169 169 { 170 170 if (currentNode.IsHeader() && currentNode.Next.IsFooter()) { … … 181 181 182 182 //Update counters 183 this.levels--;183 levels--; 184 184 185 185 currentNode = belowNode; //scan down … … 197 197 198 198 //Add levels to entire list if necessary 199 int newLevelCount = valueLevels - this.levels; //number of levels missing199 int newLevelCount = valueLevels - levels; //number of levels missing 200 200 while (newLevelCount > 0) { 201 201 //Create new level … … 203 203 204 204 //Link down 205 newLevel.Below = t his.topLeft;206 t his.topLeft.Above = newLevel;207 t his.topLeft = newLevel; //update reference to most top-left node205 newLevel.Below = topLeft; 206 topLeft.Above = newLevel; 207 topLeft = newLevel; //update reference to most top-left node 208 208 209 209 //Update counters 210 210 newLevelCount--; 211 this.levels++;211 levels++; 212 212 } 213 213 214 214 //Insert the value in the proper position, creating as many levels as was randomly determined 215 SkipListNode<T> currentNode = t his.topLeft;215 SkipListNode<T> currentNode = topLeft; 216 216 SkipListNode<T> lastNodeAbove = null; //keeps track of the upper-level nodes in a tower 217 int currentLevel = this.levels - 1;217 int currentLevel = levels - 1; 218 218 219 219 while (currentLevel >= 0 && currentNode != null) { … … 256 256 } 257 257 258 this.size++; //update count258 size++; //update count 259 259 } 260 260 … … 263 263 /// </summary> 264 264 public virtual SkipListNode<T> Find(T value) { 265 SkipListNode<T> foundNode = t his.topLeft;265 SkipListNode<T> foundNode = topLeft; 266 266 267 267 //Look for the highest-level node with an element value matching the parameter value … … 286 286 /// </summary> 287 287 public virtual SkipListNode<T> FindLowest(T value) { 288 SkipListNode<T> valueNode = this.Find(value);289 return this.FindLowest(valueNode);288 SkipListNode<T> valueNode = Find(value); 289 return FindLowest(valueNode); 290 290 } 291 291 … … 309 309 /// </summary> 310 310 public virtual SkipListNode<T> FindHighest(T value) { 311 SkipListNode<T> valueNode = this.Find(value);312 return this.FindHighest(valueNode);311 SkipListNode<T> valueNode = Find(value); 312 return FindHighest(valueNode); 313 313 } 314 314 … … 332 332 /// </summary> 333 333 public virtual bool Contains(T value) { 334 return ( this.Find(value) != null);334 return (Find(value) != null); 335 335 } 336 336 … … 339 339 /// </summary> 340 340 public virtual bool Remove(T value) { 341 SkipListNode<T> valueNode = this.FindHighest(value);342 return this.Remove(valueNode);341 SkipListNode<T> valueNode = FindHighest(value); 342 return Remove(valueNode); 343 343 } 344 344 … … 352 352 //Make sure node is top-level node in it's tower 353 353 if (valueNode.Above != null) 354 valueNode = this.FindHighest(valueNode);354 valueNode = FindHighest(valueNode); 355 355 356 356 //---Delete nodes going down the tower … … 372 372 373 373 //update counter 374 this.size--;374 size--; 375 375 376 376 //Clean up the Skip List by removing levels that are now empty 377 this.clearEmptyLevels();377 clearEmptyLevels(); 378 378 379 379 return true; … … 385 385 /// </summary> 386 386 public virtual void Clear() { 387 SkipListNode<T> currentNode = this.Head;387 SkipListNode<T> currentNode = Head; 388 388 389 389 while (currentNode != null) { … … 391 391 392 392 if (!currentNode.IsHeader() && !currentNode.IsFooter()) { 393 this.Remove(currentNode);393 Remove(currentNode); 394 394 } 395 395 … … 409 409 /// </summary> 410 410 public virtual void CopyTo(T[] array, int startIndex) { 411 IEnumerator<T> enumerator = this.GetEnumerator();411 IEnumerator<T> enumerator = GetEnumerator(); 412 412 413 413 for (int i = startIndex; i < array.Length; i++) { … … 423 423 /// </summary> 424 424 public virtual int GetHeight(T value) { 425 SkipListNode<T> valueNode = this.FindLowest(value);426 return this.GetHeight(valueNode);425 SkipListNode<T> valueNode = FindLowest(value); 426 return GetHeight(valueNode); 427 427 } 428 428 … … 459 459 /// </summary> 460 460 IEnumerator IEnumerable.GetEnumerator() { 461 return this.GetEnumerator();461 return GetEnumerator(); 462 462 } 463 463 … … 480 480 object IEnumerator.Current 481 481 { 482 get { return this.Current; }482 get { return Current; } 483 483 } 484 484 … … 493 493 public bool MoveNext() { 494 494 if (current == null) 495 current = this.skipList.Head.Next; //Head is header node, start after495 current = skipList.Head.Next; //Head is header node, start after 496 496 else 497 497 current = current.Next; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Pool/PooledList.cs
r14777 r14908 7 7 public class PooledList<T> : List<T>, IPooledObject { 8 8 public void Reset() { 9 this.Clear();9 Clear(); 10 10 } 11 11 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Pool/PooledObject.cs
r14834 r14908 16 16 17 17 public virtual void Dispose() { 18 this.resetor(this.item);19 this.pool.Free(this);18 resetor(item); 19 pool.Free(this); 20 20 } 21 21 22 22 public void Reset() { 23 this.resetor(this.item);23 resetor(item); 24 24 } 25 25 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Tree/TreeNode.cs
r14777 r14908 15 15 16 16 public void Add(T value) { 17 this.Children.Add(new TreeNode<T>(value));17 Children.Add(new TreeNode<T>(value)); 18 18 } 19 19 20 20 public void AddNode(TreeNode<T> node) { 21 this.Children.Add(node);21 Children.Add(node); 22 22 } 23 23
Note: See TracChangeset
for help on using the changeset viewer.