Changeset 1557


Ignore:
Timestamp:
Jun 1, 2010, 4:57:26 PM (12 years ago)
Author:
Sven Rech
Message:

some minor quadratic sieve changes

Location:
trunk/CrypPlugins/QuadraticSieve
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/QuadraticSieve/PeerToPeer.cs

    r1546 r1557  
    4242        private bool stopLoadStoreThread;
    4343        private QuadraticSievePresentation quadraticSieveQuickWatchPresentation;
    44 
    45         public PeerToPeer(QuadraticSievePresentation presentation)
     44        private AutoResetEvent yieldEvent;
     45
     46        public PeerToPeer(QuadraticSievePresentation presentation, AutoResetEvent yieldEvent)
    4647        {
    4748            quadraticSieveQuickWatchPresentation = presentation;
     49            this.yieldEvent = yieldEvent;
    4850        }
    4951
     
    5456                return null;
    5557
    56             MemoryStream memStream = new MemoryStream();           
     58            byte[] decompressedYield = decompressYield(yield);
     59           
     60            return decompressedYield;
     61        }
     62
     63        private static byte[] decompressYield(byte[] yield)
     64        {
     65            MemoryStream memStream = new MemoryStream();
    5766            DeflateStream defStream = new DeflateStream(memStream, CompressionMode.Decompress);
    5867            memStream.Write(yield, 0, yield.Length);
     
    6069            MemoryStream memStream2 = new MemoryStream();
    6170            defStream.CopyTo(memStream2);
     71            defStream.Close();
    6272            byte[] decompressedYield = memStream2.ToArray();
    63            
    6473            return decompressedYield;
    6574        }
     
    9099                        SetProgressYield(loadIndex, YieldStatus.OthersLoaded);
    91100                        loadIndex++;
     101                        yieldEvent.Set();
    92102                    }
    93103                    else                //if there is nothing left to load, we can slow down.
     
    117127        private string HeadIdentifier()
    118128        {
    119             return channel + "#" + factor + "HEAD";
     129            return channel + "#" + number + "-" + factor + "HEAD";
    120130        }
    121131
     
    127137        private string YieldIdentifier(int index)
    128138        {
    129             return channel + "#" + factor + "!" + index;
     139            return channel + "#" + number + "-" + factor + "!" + index;
    130140        }
    131141
     
    161171            DeflateStream defStream = new DeflateStream(memStream, CompressionMode.Compress);
    162172            defStream.Write(serializedYield, 0, serializedYield.Length);
     173            defStream.Close();
    163174            byte[] compressedYield = memStream.ToArray();
     175
     176            byte[] decompr = decompressYield(compressedYield);
     177            Debug.Assert(decompr.Length == serializedYield.Length);
    164178
    165179            storequeue.Enqueue(compressedYield);
  • trunk/CrypPlugins/QuadraticSieve/QuadraticSieve.cs

    r1545 r1557  
    9898            QuickWatchPresentation = new QuadraticSievePresentation();
    9999
    100             peerToPeer = new PeerToPeer(quadraticSieveQuickWatchPresentation);
     100            peerToPeer = new PeerToPeer(quadraticSieveQuickWatchPresentation, yieldEvent);
    101101           
    102102            quadraticSieveQuickWatchPresentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     
    535535            TimeSpan diff = DateTime.Now - start_sieving_time;
    536536            double msleft = (diff.TotalMilliseconds / (num_relations - start_relations)) * (max_relations - num_relations);
    537             if (msleft > 0)
     537            if (msleft > 0 && !double.IsInfinity(msleft))
    538538            {
    539539                TimeSpan ts = new TimeSpan(0, 0, 0, 0, (int)msleft);
     
    556556                quadraticSieveQuickWatchPresentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    557557                {
    558                     string size = ((sumSize / 1024.0) / 1024).ToString().Substring(0, 3);
     558                    string s = ((sumSize / 1024.0) / 1024).ToString();
     559                    string size = s.Substring(0, (s.Length < 3) ? s.Length : 3);
    559560                    quadraticSieveQuickWatchPresentation.relationsInfo.Content = size + " MB compressed relation data available!";
    560561                }, null);
Note: See TracChangeset for help on using the changeset viewer.