Exemple #1
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);
        }
Exemple #2
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);
        }