当前位置: 首页>>代码示例>>C#>>正文


C# Service.NumUrls方法代码示例

本文整理汇总了C#中Service.NumUrls方法的典型用法代码示例。如果您正苦于以下问题:C# Service.NumUrls方法的具体用法?C# Service.NumUrls怎么用?C# Service.NumUrls使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Service的用法示例。


在下文中一共展示了Service.NumUrls方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

 public static void Main(string[] args)
 {
     if (args.Length != 2) {
       Console.Error.WriteLine("Usage: SHS.SCC1 <leader> <store>");
     } else {
       var sw = Stopwatch.StartNew();
       var store = new Service(args[0]).OpenStore(Guid.Parse(args[1]));
       long numUids = store.NumUrls();
       var bv = new BitVector(numUids);  // All false at creation
       var stk = new LongStack(1 << 23, "scc");
       foreach (long u in store.Uids()) {
     if (!bv[store.UidToLid(u)]) {
       Frame frame = new Frame(null, u, store, Dir.Fwd, bv);
       while (frame != null) {
         while (frame.linkPos < frame.links.Length) {
           long v = frame.links[frame.linkPos++];
           if (!bv[store.UidToLid(v)]) {
             frame = new Frame(frame, v, store, Dir.Fwd, bv);
           }
         }
         stk.Push(frame.uid);
         frame = frame.parent;
       }
     }
       }
       using (var sccWr = new BinaryWriter(new BufferedStream(new FileStream("scc-main.bin", FileMode.Create, FileAccess.Write)))) {
     using (var idxWr = new BinaryWriter(new BufferedStream(new FileStream("scc-index.bin", FileMode.Create, FileAccess.Write)))) {
       long numSCCs = 0;
       long sccPos = 0;
       bv.SetAll(false);
       for (long i = 0; i < numUids; i++) {
         long u = stk.Pop();
         if (!bv[store.UidToLid(u)]) {
           numSCCs++;
           long sccSize = 0;
           Frame frame = new Frame(null, u, store, Dir.Bwd, bv);
           while (frame != null) {
             while (frame.linkPos < frame.links.Length) {
               long v = frame.links[frame.linkPos++];
               if (!bv[store.UidToLid(v)]) {
                 frame = new Frame(frame, v, store, Dir.Bwd, bv);
               }
             }
             sccWr.Write(frame.uid);
             sccSize++;
             frame = frame.parent;
           }
           idxWr.Write(sccSize);
           idxWr.Write(sccPos);
           sccPos += sccSize;
         }
       }
     }
       }
       store.Close();
       Console.WriteLine("Done. Job took {0} seconds.", 0.001 * sw.ElapsedMilliseconds);
     }
 }
开发者ID:pszmyd,项目名称:SHS,代码行数:58,代码来源:SCC1.cs

示例2: Main

 public static void Main(string[] args)
 {
     if (args.Length != 4) {
       Console.Error.WriteLine("Usage: SHS.PageRank <leader> <store> <d> <iters>");
     } else {
       var sw = Stopwatch.StartNew();
       var store = new Service(args[0]).OpenStore(Guid.Parse(args[1]));
       double d = double.Parse(args[2]);
       int numIters = int.Parse(args[3]);
       long n = store.NumUrls();
       using (var wr = new BinaryWriter(new BufferedStream(new FileStream("pr-scores-" + 0 + ".bin", FileMode.Create, FileAccess.Write)))) {
     for (long i = 0; i < n; i++) wr.Write(1.0 / n);
       }
       var scores = store.AllocateUidState<double>();
       var uidBatch = new Batch<long>(50000);
       for (int k = 0; k < numIters; k++) {
     scores.SetAll(x => d / n);
     using (var rd = new BinaryReader(new BufferedStream(new FileStream("pr-scores-" + k + ".bin", FileMode.Open, FileAccess.Read)))) {
       foreach (long u in store.Uids()) {
         uidBatch.Add(u);
         if (uidBatch.Full || store.IsLastUid(u)) {
           var linkBatch = store.BatchedGetLinks(uidBatch, Dir.Fwd);
           var uniqLinks = new UidMap(linkBatch);
           var scoreArr = scores.GetMany(uniqLinks);
           foreach (var links in linkBatch) {
             double f = (1.0 - d) * rd.ReadDouble() / links.Length;
             foreach (var link in links) {
               scoreArr[uniqLinks[link]] += f;
             }
           }
           scores.SetMany(uniqLinks, scoreArr);
           uidBatch.Reset();
         }
       }
     }
     using (var wr = new BinaryWriter(new BufferedStream(new FileStream("pr-scores-" + (k + 1) + ".bin", FileMode.Create, FileAccess.Write)))) {
       foreach (var us in scores.GetAll()) wr.Write(us.val);
     }
     File.Delete("pr-scores-" + k + ".bin");
     Console.WriteLine("Iteration {0} complete", k);
       }
       Console.WriteLine("Done. {0} iterations took {1} seconds.", numIters, 0.001 * sw.ElapsedMilliseconds);
     }
 }
开发者ID:pszmyd,项目名称:SHS,代码行数:44,代码来源:PageRank.cs

示例3: Main

    public static void Main(string[] args)
    {
        if (args.Length != 4) {
          Console.Error.WriteLine("Usage: SHS.PageRankFT <leader> <store> <d> <iters>");
        } else {
          var sw = Stopwatch.StartNew();
          var store = new Service(args[0]).OpenStore(Guid.Parse(args[1]));

          Action<Action> Checkpointed = delegate(Action checkpointedBlock) {
        while (true) {
          try {
            checkpointedBlock();
            store.Checkpoint();
            break;
          } catch (ServerFailure) {
            Console.Error.WriteLine("Restarting from checkpoint");
            // go again
          }
        }
          };

          double d = double.Parse(args[2]);
          int numIters = int.Parse(args[3]);
          long n = store.NumUrls();

          UidState<double> oldScores = null, newScores = null;

          Checkpointed(delegate() {
        newScores = store.AllocateUidState<double>();
        oldScores = store.AllocateUidState<double>();
        oldScores.SetAll(uid => 1.0 / n);
          });

          for (int k = 0; k < numIters; k++) {
        Checkpointed(delegate() {
          var uidBatch = new Batch<long>(50000);
          newScores.SetAll(x => d / n);
          foreach (long u in store.Uids()) {
            uidBatch.Add(u);
            if (uidBatch.Full || store.IsLastUid(u)) {
              var linkBatch = store.BatchedGetLinks(uidBatch, Dir.Fwd);
              var newMap = new UidMap(linkBatch);
              var oldSc = oldScores.GetMany(uidBatch);
              var newSc = newScores.GetMany(newMap);
              for (int i = 0; i < uidBatch.Count; i++) {
                var links = linkBatch[i];
                double f = (1.0 - d) * oldSc[i] / links.Length;
                foreach (var link in links) {
                  newSc[newMap[link]] += f;
                }
              }
              newScores.SetMany(newMap, newSc);
              uidBatch.Reset();
            }
          }
        });
        var tmp = newScores; newScores = oldScores; oldScores = tmp;
        Console.WriteLine("Done with iteration {0}", k);
          }
          using (var wr = new BinaryWriter(new BufferedStream(new FileStream("pr-scores.bin", FileMode.Create, FileAccess.Write)))) {
        foreach (var us in newScores.GetAll()) wr.Write(us.val);
          }
          Console.WriteLine("Done. {0} iterations took {1} seconds.", numIters, 0.001 * sw.ElapsedMilliseconds);
        }
    }
开发者ID:pszmyd,项目名称:SHS,代码行数:65,代码来源:PageRankFT.cs


注:本文中的Service.NumUrls方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。