Example #1
0
        // <doc>
        // <desc>
        //     Adds the a node to the right of the specified node, given a string.
        // </desc>
        // </doc>
        //

        private MTNameTableNode AddRight(MTNameTableNode node, ref MTNameTableName name, bool fLock)
        {
            MTNameTableNode newNode = null;

            if (fLock)
            {
                LockCookie lc = rwLock.UpgradeToWriterLock(timeout);

                // recheck for failsafe against race-condition
                if (node.rightNode == null)
                {
                    newNode            = new MTNameTableNode(ref name);
                    node.rightNode     = newNode;
                    newNode.parentNode = node;
                }
                else
                {
                    // try again, with write-lock active
                    newNode = Add(ref name, false);
                }

                rwLock.DowngradeFromWriterLock(ref lc);
            }
            else
            {
                newNode            = new MTNameTableNode(ref name);
                node.rightNode     = newNode;
                newNode.parentNode = node;
            }

            return(newNode);
        }
Example #2
0
        private MTNameTableNode Add(ref MTNameTableName name, bool fLock)
        {
            if (fLock)
            {
                rwLock.AcquireReaderLock(timeout);
            }

            MTNameTableNode currentNode = rootNode;

            while (true)
            {
                if (currentNode == null)
                {
                    currentNode = AddRoot(ref name, fLock);
                    break;
                }
                else
                {
                    Int64 d = currentNode.Compare(ref name);

                    if (d == 0)
                    {
                        Promote(currentNode);
                        break;
                    }
                    else if (d < 0)
                    {
                        if (currentNode.leftNode == null)
                        {
                            currentNode = AddLeft(currentNode, ref name, fLock);
                            break;
                        }
                        else
                        {
                            currentNode = currentNode.leftNode;
                        }
                    }
                    else
                    {
                        if (currentNode.rightNode == null)
                        {
                            currentNode = AddRight(currentNode, ref name, fLock);
                            break;
                        }
                        else
                        {
                            currentNode = currentNode.rightNode;
                        }
                    }
                }
            }

            if (fLock)
            {
                rwLock.ReleaseReaderLock();
            }

            return(currentNode);
        }
Example #3
0
        // <doc>
        // <desc>
        //      Find the matching string atom given a string
        // </desc>
        // </doc>
        //

        public override String Get(String value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            MTNameTableName name = new MTNameTableName(value);

            return(Get(ref name));
        }
Example #4
0
 internal Int64 Compare(ref MTNameTableName name)
 {
     if (name.array != null)
     {
         return(Compare(name.hash, name.array, name.start, name.len));
     }
     else
     {
         return(Compare(name.hash, name.str));
     }
 }
Example #5
0
        // <doc>
        // <desc>
        //      Find the matching string atom given a string, or
        //      insert a new one.
        // </desc>
        // </doc>
        //

        public override String Add(String value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            MTNameTableName name = new MTNameTableName(value);

            return(Add(ref name, rwLock != null).value);
        }
Example #6
0
        internal MTNameTableNode(ref MTNameTableName name)
        {
            if (name.str != null)
            {
                value = name.str;
            }
            else
            {
                value = new String(name.array, name.start, name.len);
            }

            this.hash = name.hash;
        }
Example #7
0
        private String Get(ref MTNameTableName nn)
        {
            String name = null;

            if (rootNode != null)
            {
                if (rwLock != null)
                {
                    rwLock.AcquireReaderLock(timeout);
                }

                MTNameTableNode currentNode = rootNode;

                while (true)
                {
                    Int64 d = currentNode.Compare(ref nn);

                    if (d == 0)
                    {
                        Promote(currentNode);
                        name = currentNode.value;
                        break;
                    }
                    else if (d < 0)
                    {
                        if (currentNode.leftNode == null)
                        {
                            break;
                        }

                        currentNode = currentNode.leftNode;
                    }
                    else
                    {
                        if (currentNode.rightNode == null)
                        {
                            break;
                        }

                        currentNode = currentNode.rightNode;
                    }
                }

                if (rwLock != null)
                {
                    rwLock.ReleaseReaderLock();
                }
            }

            return(name);
        }
Example #8
0
        public override String Get(char[] key, int start, int len)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            else
            {
                if ((start < 0) || (len < 0) || (start > key.Length - len))
                {
                    throw new ArgumentOutOfRangeException();
                }
            }

            MTNameTableName name = new MTNameTableName(key, start, len);

            return(Get(ref name));
        }
 internal Int64 Compare( ref MTNameTableName name ) {
     if (name.array != null) {
         return Compare( name.hash, name.array, name.start, name.len );
     }
     else {
         return Compare( name.hash, name.str );
     }
 }
        internal MTNameTableNode(ref MTNameTableName name ) {
            if (name.str != null) {
                value = name.str;
            }
            else {
                value = new String(name.array, name.start, name.len);
            }

            this.hash = name.hash;
        }