Пример #1
0
            public void ForEachSatisfiedValue(ContentName name, int part, Action <T> f)
            {
                TableTreeNode child;

                if (part < name.ComponentCount && children.TryGetValue(name [part], out child))
                {
                    child.ForEachSatisfiedValue(name, part + 1, f);
                }
                foreach (T content in contents)
                {
                    f(content);
                }
            }
Пример #2
0
        public string[] GetSuffix(ContentName prefix)
        {
            if (!prefix.IsPrefixOf(this))
            {
                return(null);
            }

            string[] ret = new string[NameParts.Length - prefix.NameParts.Length];
            for (int i = prefix.ComponentCount, j = 0; i < ComponentCount; i++, j++)
            {
                ret[j] = NameParts[i];
            }
            return(ret);
        }
Пример #3
0
 public bool IsPrefixOf(ContentName another)
 {
     if (NameParts.Length > another.NameParts.Length)
     {
         return(false);
     }
     for (int i = 0; i < NameParts.Length; i++)
     {
         if (!NameParts[i].Equals(another.NameParts[i]))
         {
             return(false);
         }
     }
     return(true);
 }
Пример #4
0
            public void ForEachSatisfiedPair(ContentName name, int part, Action <ContentName, T> f)
            {
                TableTreeNode child;

                if (part < name.ComponentCount && children.TryGetValue(name [part], out child))
                {
                    child.ForEachSatisfiedPair(name, part + 1, f);
                }
                if (contents.Count > 0)
                {
                    ContentName n = new ContentName(name, part);
                    foreach (T content in contents)
                    {
                        f(n, content);
                    }
                }
            }
Пример #5
0
 public void ForEachPair(Action <ContentName, T> f, LinkedList <string> parts)
 {
     if (contents.Count > 0)
     {
         ContentName name = new ContentName(parts);
         foreach (T t in contents)
         {
             f(name, t);
         }
     }
     foreach (var child in children)
     {
         parts.AddLast(child.Key);
         child.Value.ForEachPair(f, parts);
         parts.RemoveLast();
     }
 }
Пример #6
0
        public override bool Equals(object obj)
        {
            ContentName another = obj as ContentName;

            if (another == null || NameParts.Length != another.NameParts.Length)
            {
                return(false);
            }
            for (int i = 0; i < NameParts.Length; i++)
            {
                if (!NameParts[i].Equals(another.NameParts[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #7
0
            public bool ForEachLongestPrefixMatchingValue(ContentName name, int part, Action <T> f)
            {
                TableTreeNode child;

                if (part < name.ComponentCount && children.TryGetValue(name [part], out child) && child.ForEachLongestPrefixMatchingValue(name, part + 1, f))
                {
                    return(true);
                }
                if (contents.Count > 0)
                {
                    foreach (T content in contents)
                    {
                        f(content);
                    }
                    return(true);
                }
                return(false);
            }
Пример #8
0
            public bool RemoveSatisfiedValues(ContentName name, int part, Action <T> f)
            {
                TableTreeNode child;

                if (part < name.ComponentCount && children.TryGetValue(name [part], out child))
                {
                    if (child.RemoveSatisfiedValues(name, part + 1, f))
                    {
                        children.Remove(name [part]);
                    }
                }
                if (contents.Count > 0)
                {
                    foreach (T content in contents)
                    {
                        f(content);
                    }
                    contents.Clear();
                }
                return(children.Count == 0);
            }
Пример #9
0
 public void AddValue(ContentName name, int part, T value, out bool valueAdded, out bool nameAdded, bool exclude)
 {
     if (part == name.ComponentCount)
     {
         if (exclude && contents.Contains(value))
         {
             nameAdded  = false;
             valueAdded = false;
         }
         contents.AddLast(value);
         nameAdded  = contents.Count == 1;
         valueAdded = true;
     }
     else
     {
         string        s = name [part];
         TableTreeNode child;
         if (!children.TryGetValue(s, out child))
         {
             children.Add(s, child = new TableTreeNode());
         }
         child.AddValue(name, part + 1, value, out valueAdded, out nameAdded, exclude);
     }
 }
Пример #10
0
 public T LookupExactOrAddNew(ContentName name, int part, Func <T> f)
 {
     if (part == name.ComponentCount)
     {
         if (contents.Count > 0)
         {
             return(contents.First.Value);
         }
         else
         {
             return(contents.AddLast(f()).Value);
         }
     }
     else
     {
         string        s = name [part];
         TableTreeNode child;
         if (!children.TryGetValue(s, out child))
         {
             children.Add(s, child = new TableTreeNode());
         }
         return(child.LookupExactOrAddNew(name, part + 1, f));
     }
 }
Пример #11
0
 /// <summary>
 /// Iterate through all the values the target can satisfy
 /// More light-weight compared to ForEachLongestPrefixMatch. Use this when you don't really need the names.
 /// </summary>
 /// <param name="target">name to match</param>
 /// <param name="f">action on each value</param>
 public void ForEachLongestPrefixMatchingValue(ContentName target, Action <T> f)
 {
     Root.ForEachLongestPrefixMatchingValue(target, 0, f);
 }
Пример #12
0
 public ContentName GetChild(ContentName suffix)
 {
     return(GetChild(suffix.NameParts));
 }
Пример #13
0
 public Interest(ContentName name, byte interestType) : base(PACKET_INTEREST)
 {
     Name         = name;
     InterestType = interestType;
 }
Пример #14
0
 public T LookupExactOrAddNew(ContentName target, Func <T> generator)
 {
     return(Root.LookupExactOrAddNew(target, 0, generator));
 }
Пример #15
0
 /// <summary>
 /// Remove all the values satisfying the target name
 ///
 /// </summary>
 /// <param name="target">name to remove</param>
 /// <param name="f">action on each value (to-remove)</param>
 public void RemoveSatisfiedValues(ContentName target, Action <T> f)
 {
     Root.RemoveSatisfiedValues(target, 0, f);
 }
Пример #16
0
 /// <summary>
 /// Iterate through all the pairs that the target can satisfy
 /// </summary>
 /// <param name="target">name to satisfy</param>
 /// <param name="f">action on each pair</param>
 public void ForEachSatisfiedPair(ContentName target, Action <ContentName, T> f)
 {
     Root.ForEachSatisfiedPair(target, 0, f);
 }
Пример #17
0
 /// <summary>
 /// Add a value associated with content name to the table
 /// </summary>
 /// <param name="name">name of the content</param>
 /// <param name="value">associated object</param>
 /// <param name="exclude">if exclude add</param>
 /// <param name="nameAdded">if a new name has been added</param>
 /// <returns>if content is added</returns>
 public void Add(ContentName name, T value, out bool nameAdded, out bool valueAdded, bool exclude = false)
 {
     Trace.Assert(name != null && value != null);
     Root.AddValue(name, 0, value, out valueAdded, out nameAdded, exclude);
 }
Пример #18
0
 /// <summary>
 /// Iterate through all the values that the target can satisfy
 /// More light-weight compared to ForEachSatisfiedPair. Use this when you don't really need the names.
 /// </summary>
 /// <param name="target">name to satisfy</param>
 /// <param name="f">action on each value</param>
 public void ForEachSatisfiedValue(ContentName target, Action <T> f)
 {
     Root.ForEachSatisfiedValue(target, 0, f);
 }
Пример #19
0
 /// <summary>
 /// Iterate through all the pairs the target can satisfy
 /// </summary>
 /// <param name="target">name to match</param>
 /// <param name="f">action on each match</param>
 public void ForEachLongestPrefixMatch(ContentName target, Action <ContentName, T> f)
 {
     Root.ForEachLongestPrefixMatch(target, 0, f);
 }
Пример #20
0
 public Data(Stream stream) : base(PACKET_DATA, stream)
 {
     Name    = ContentName.ReadFrom(stream);
     Content = new RandomContent(stream);
 }
Пример #21
0
 public Interest(Stream stream) : base(PACKET_INTEREST, stream)
 {
     InterestType = (byte)stream.ReadByte();
     Name         = ContentName.ReadFrom(stream);
 }
Пример #22
0
 /// <summary>
 /// Remove all the values matching the target name (the whole sub-tree)
 /// </summary>
 /// <param name="target">name to remove</param>
 /// <param name="f">action on each match (to-remove)</param>
 public void RemoveMatches(ContentName target, Action <ContentName, T> f)
 {
     Root.RemoveSatisfiedMatches(target, 0, f);
 }
Пример #23
0
 public ContentName(ContentName name, int partCount) : this(SubArray(name.NameParts, partCount))
 {
 }
Пример #24
0
 public Data(ContentName name, ISerializable content) : base(PACKET_DATA)
 {
     Name    = name;
     Content = content;
 }