Applied patch from Jan Limpens 'ReflectionBasedDictionaryAdapter needs to check if...
[castle.git] / Core / Castle.Core / Internal / GraphSets.cs
blob7690ecb4ab83964f90af6f5d189b5202d4eefaf4
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.Core.Internal
17 using System.Collections;
18 using System.Collections.Generic;
20 internal enum VertexColor
22 NotInThisSet,
23 /// <summary>
24 /// The node has not been visited yet
25 /// </summary>
26 White,
27 /// <summary>
28 /// This node is in the process of being visited
29 /// </summary>
30 Gray,
31 /// <summary>
32 /// This now was visited
33 /// </summary>
34 Black
37 /// <summary>
38 /// Represents a collection of objects
39 /// which are guaranted to be unique
40 /// and holds a color for them
41 /// </summary>
42 internal class ColorsSet
44 private IDictionary<IVertex, VertexColor> items = new Dictionary<IVertex, VertexColor>();
46 public ColorsSet(IVertex[] items)
48 foreach(IVertex item in items)
50 Set(item, VertexColor.White);
54 public void Set(IVertex item, VertexColor color)
56 items[item] = color;
59 public VertexColor ColorOf(IVertex item)
61 if (!items.ContainsKey(item)) return VertexColor.NotInThisSet;
62 return (VertexColor) items[item];
66 /// <summary>
67 /// Holds a timestamp (integer)
68 /// for a given item
69 /// </summary>
70 internal class TimestampSet
72 private IDictionary<IVertex, int> items = new Dictionary<IVertex, int>();
74 public TimestampSet()
78 public void Register(IVertex item, int time)
80 items[item] = time;
83 public int TimeOf(IVertex item)
85 return (int) items[item];