Пример #1
0
            internal object remove(ulong key, int keyLength)
            {
                object obj;
#endif
                if (keyLength >= this.keyLength)
                {
                    if (key == this.key && keyLength == this.keyLength)
                    {
                        obj      = this.obj;
                        this.obj = null;
                        return(obj);
                    }
                    else
                    {
                        int   keyLengthCommon = getCommonPartLength(key, keyLength, this.key, this.keyLength);
                        int   keyLengthDiff   = keyLength - keyLengthCommon;
                        ulong keyCommon       = key >> keyLengthDiff;
                        ulong keyDiff         = key - (keyCommon << keyLengthDiff);

                        if (firstBit(keyDiff, keyLengthDiff) == 1)
                        {
                            if (childOne != null)
                            {
                                obj = childOne.findBestMatch(keyDiff, keyLengthDiff);
                                if (obj != null)
                                {
                                    if (childOne.isNotUsed())
                                    {
                                        Modify();
                                        childOne.Deallocate();
                                        childOne = null;
                                    }
                                    return(obj);
                                }
                            }
                        }
                        else
                        {
                            if (childZero != null)
                            {
                                obj = childZero.findBestMatch(keyDiff, keyLengthDiff);
                                if (obj != null)
                                {
                                    if (childZero.isNotUsed())
                                    {
                                        Modify();
                                        childZero.Deallocate();
                                        childZero = null;
                                    }
                                    return(obj);
                                }
                            }
                        }
                    }
                }
                return(null);
            }
Пример #2
0
            internal T remove(ulong key, int keyLength)
            {
                T obj;

                if (keyLength < this.keyLength)
                {
                    return(null);
                }

                if (key == this.key && keyLength == this.keyLength)
                {
                    obj      = this.obj;
                    this.obj = null;
                    return(obj);
                }

                int   keyLengthCommon = getCommonPart(key, keyLength, this.key, this.keyLength);
                int   keyLengthDiff   = keyLength - keyLengthCommon;
                ulong keyCommon       = key >> keyLengthDiff;
                ulong keyDiff         = key - (keyCommon << keyLengthDiff);

                if (firstDigit(keyDiff, keyLengthDiff) == 1)
                {
                    if (childOne == null)
                    {
                        return(null);
                    }

                    obj = childOne.findBestMatch(keyDiff, keyLengthDiff);
                    if (obj == null)
                    {
                        return(null);
                    }

                    if (childOne.isNotUsed())
                    {
                        Modify();
                        childOne.Deallocate();
                        childOne = null;
                    }
                    return(obj);
                }

                if (childZero == null)
                {
                    return(null);
                }

                obj = childZero.findBestMatch(keyDiff, keyLengthDiff);
                if (obj == null)
                {
                    return(null);
                }

                if (childZero.isNotUsed())
                {
                    Modify();
                    childZero.Deallocate();
                    childZero = null;
                }
                return(obj);
            }