Ignore:
Timestamp:
Jun 23, 2010, 2:04:44 PM (12 years ago)
Author:
Paul Lelgemann
Message:

o Work on the distributed KeySearcher cache

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/KeySearcher/P2P/Tree/Node.cs

    r1674 r1693  
    1 using System.Numerics;
     1using System;
     2using System.Numerics;
    23using KeySearcher.Helper;
    34using KeySearcher.P2P.Exceptions;
     
    1314        private NodeBase leftChild;
    1415        private NodeBase rightChild;
     16        private bool leftChildReserved;
     17        private bool rightChildReserved;
    1518
    1619        public Node(StorageHelper storageHelper, KeyQualityHelper keyQualityHelper, Node parentNode, BigInteger @from, BigInteger to, string distributedJobIdentifier)
     
    6265        }
    6366
    64         public override Leaf CalculatableLeaf(bool useReservedNodes)
     67        public override void UpdateCache()
    6568        {
    6669            LoadOrUpdateChildNodes();
    6770
     71            leftChildReserved = LeftChildFinished || leftChild.IsReserverd();
     72            rightChildReserved = RightChildFinished || (rightChild != null && rightChild.IsReserverd());
     73        }
     74
     75        public override Leaf CalculatableLeaf(bool useReservedNodes)
     76        {
     77            // LoadOrUpdateChildNodes();
     78
    6879            // Left child not finished and not reserved (or reserved leafs are allowed)
    69             if (!LeftChildFinished && (!leftChild.IsReserverd() || useReservedNodes))
     80            if (!LeftChildFinished && (!leftChildReserved || useReservedNodes))
    7081            {
    7182                return leftChild.CalculatableLeaf(useReservedNodes);
     
    8697                LeftChildFinished = true;
    8798                leftChild = null;
     99                UpdateCache();
    88100                return;
    89101            }
     
    93105                RightChildFinished = true;
    94106                rightChild = null;
     107                UpdateCache();
    95108                return;
    96109            }
     
    99112        public override bool IsReserverd()
    100113        {
    101             LoadOrUpdateChildNodes();
     114            // LoadOrUpdateChildNodes();
    102115
    103             var leftChildFinishedOrReserved = LeftChildFinished || leftChild.IsReserverd();
     116            // var leftChildFinishedOrReserved = LeftChildFinished || leftChildReserved;
    104117
     118            if (LeftChildFinished && !RightChildFinished)
     119            {
     120                return rightChildReserved;
     121            }
     122
     123            if (!LeftChildFinished && RightChildFinished)
     124            {
     125                return leftChildReserved;
     126            }
     127
     128            if (!LeftChildFinished && !RightChildFinished && rightChildReserved)
     129            {
     130                return leftChildReserved;
     131            }
     132
     133            return rightChildReserved;
     134            /*
    105135            if (leftChildFinishedOrReserved && !RightChildFinished)
    106136            {
    107                 return rightChild.IsReserverd();
     137                return rightChildReserved;
    108138            }
    109139
    110             return !LeftChildFinished && leftChild.IsReserverd();
     140            return !LeftChildFinished && leftChildReserved;*/
    111141        }
    112142
Note: See TracChangeset for help on using the changeset viewer.