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


C# Service.BatchedGetDegree方法代码示例

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


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

示例1: Main

 public static void Main(string[] args)
 {
     if (args.Length != 3) {
       Console.Error.WriteLine("Usage: SHS.ASP <leader> <store> [f|b|u]");
     } else {
       var sw = Stopwatch.StartNew();
       var shs = new Service(args[0]).OpenStore(Guid.Parse(args[1]));
       var dists = shs.AllocateUidState<byte>();
       var seeds = shs.AllocateUidState<long>();
       var cands = shs.AllocateUidState<bool>();
       var batch = new Batch<long>(1000000);
       long numCands = 0;
       bool fwd = args[2] == "f" || args[2] == "u";
       bool bwd = args[2] == "b" || args[2] == "u";
       foreach (long u in shs.Uids()) {
     batch.Add(u);
     if (batch.Full || shs.IsLastUid(u)) {
       int[] fwdDegs = shs.BatchedGetDegree(batch, Dir.Fwd);
       int[] bwdDegs = shs.BatchedGetDegree(batch, Dir.Bwd);
       bool[] isCands = new bool[batch.Count];
       for (int i = 0; i < batch.Count; i++) {
         isCands[i] = fwd && bwd ? fwdDegs[i] + bwdDegs[i] > 1 : fwdDegs[i] > 0 && bwdDegs[i] > 0;
         if (isCands[i]) numCands++;
       }
       cands.SetMany(batch, isCands);
       batch.Reset();
     }
       }
       System.Random rand = new System.Random(12345);
       int dim = 0;
       batch = new Batch<long>(1000);
       for (; (long)1 << dim <= numCands; dim++) {
     long numSeeds = (long)1 << dim;
     dists.SetAll(x => 0xff);
     seeds.SetAll(x => -1);
     double remainingSamps = numSeeds;
     double remainingCands = numCands;
     foreach (var uc in cands.GetAll()) {
       if (uc.val) {
         if (rand.NextDouble() < remainingSamps / remainingCands) {
           batch.Add(uc.uid);
           remainingSamps--;
         }
         remainingCands--;
       }
       if (batch.Full || shs.IsLastUid(uc.uid)) {
         dists.SetMany(batch, ((long[])batch).Select(x => (byte)0).ToArray());
         seeds.SetMany(batch, batch);
         batch.Reset();
       }
     }
     for (byte k = 0; k < 0xff; k++) {
       long hits = 0;
       foreach (var x in dists.GetAll()) {
         if (x.val == k) {
           batch.Add(x.uid);
           hits++;
         }
         if (batch.Full || shs.IsLastUid(x.uid)) {
           if (bwd) ProcessBatch(shs, dists, seeds, batch, (byte)(k + 1), Dir.Fwd);
           if (fwd) ProcessBatch(shs, dists, seeds, batch, (byte)(k + 1), Dir.Bwd);
           batch.Reset();
         }
       }
       if (hits == 0) break;
     }
     using (var wr = new BinaryWriter(new GZipStream(new BufferedStream(new FileStream("sketchslice-" + args[2] + "-" + dim.ToString("d2") + ".bin", FileMode.Create, FileAccess.Write)), CompressionMode.Compress))) {
       long rch = 0;  // Number of reachable URls
       foreach (var x in dists.GetAll().Zip(seeds.GetAll(), (d, s) => System.Tuple.Create(d, s))) {
         if (x.Item1.val < 0xff) rch++;
         wr.Write(x.Item1.val);
         wr.Write(x.Item2.val);
       }
     }
       }
       using (var wr = new BinaryWriter(new GZipStream(new BufferedStream(new FileStream("sketches-" + args[2] + ".bin", FileMode.Create, FileAccess.Write)), CompressionMode.Compress))) {
     wr.Write(dim);
     var readers = new BinaryReader[dim];
     for (int i = 0; i < dim; i++) {
       readers[i] = new BinaryReader(new GZipStream(new BufferedStream(new FileStream("sketchslice-" + args[2] + "-" + i.ToString("d2") + ".bin", FileMode.Open, FileAccess.Read)), CompressionMode.Decompress));
     }
     while (true) {
       try {
         for (int i = 0; i < dim; i++) {
           wr.Write(readers[i].ReadByte());
           wr.Write(readers[i].ReadInt64());
         }
       } catch (EndOfStreamException) {
         break;
       }
     }
     for (int i = 0; i < dim; i++) {
       readers[i].Close();
     }
       }
       Console.WriteLine("Done. Job took {0} seconds.", 0.001 * sw.ElapsedMilliseconds);
     }
 }
开发者ID:pszmyd,项目名称:SHS,代码行数:98,代码来源:ASP.cs

示例2: Main

 public static void Main(string[] args)
 {
     if (args.Length != 2) {
       Console.Error.WriteLine("Usage: SHS.SCC2 <leader> <store>");
     } else {
       var sw = Stopwatch.StartNew();
       var shs = new Service(args[0]).OpenStore(Guid.Parse(args[1]));
       var map = shs.AllocateUidState<int>();  // Mapping from UID to local ID
       int numVerts = 0;  // Number of core vertices
       var batch = new Batch<long>(500000);
       foreach (long u in shs.Uids()) {
     batch.Add(u);
     if (batch.Full || shs.IsLastUid(u)) {
       int[] fwdDegs = shs.BatchedGetDegree(batch, Dir.Fwd);
       int[] bwdDegs = shs.BatchedGetDegree(batch, Dir.Bwd);
       var mapChunk = new int[batch.Count];
       for (int i = 0; i < batch.Count; i++) {
         mapChunk[i] = fwdDegs[i] == 0 || bwdDegs[i] == 0 ? -1 : numVerts++;
       }
       map.SetMany(batch, mapChunk);
       batch.Reset();
     }
       }
       uint numEdges = 0;
       foreach (var up in map.GetAll()) {
     if (up.val != -1) batch.Add(up.uid);
     if (batch.Full || shs.IsLastUid(up.uid)) {
       long[][] nbors = shs.BatchedGetLinks(batch, Dir.Fwd);
       int[] mappedNbors = map.GetMany(Flatten(nbors));
       int q = 0;
       for (int i = 0; i < nbors.Length; i++) {
         for (int j = 0; j < nbors[i].Length; j++) {
           if (mappedNbors[q++] != -1) numEdges++;
         }
       }
       batch.Reset();
     }
       }
       uint[] pastLast = new uint[numVerts]; // one past last link of that page
       var links = new int[numEdges];
       int p = 0;
       uint r = 0;
       foreach (var up in map.GetAll()) {
     if (up.val != -1) batch.Add(up.uid);
     if (batch.Full || shs.IsLastUid(up.uid)) {
       long[][] nbors = shs.BatchedGetLinks(batch, Dir.Fwd);
       int[] mappedNbors = map.GetMany(Flatten(nbors));
       int q = 0;
       for (int i = 0; i < nbors.Length; i++) {
         for (int j = 0; j < nbors[i].Length; j++) {
           int id = mappedNbors[q++];
           if (id != -1) links[r++] = id;
         }
         pastLast[p++] = r;
       }
       batch.Reset();
     }
       }
       var bv = new BitVector(numVerts);  // All false at creation
       int[] stk = new int[numVerts];
       int stkPtr = stk.Length;
       for (int u = 0; u < numVerts; u++) {
     if (!bv[u]) {
       bv[u] = true;
       Frame frame = new Frame(null, u, pastLast);
       while (frame != null) {
         while (frame.ctr < pastLast[frame.id]) {
           int v = links[frame.ctr++];
           if (!bv[v]) {
             bv[v] = true;
             frame = new Frame(frame, v, pastLast);
           }
         }
         stk[--stkPtr] = frame.id;
         frame = frame.parent;
       }
     }
       }
       p = 0;
       r = 0;
       foreach (var up in map.GetAll()) {
     if (up.val != -1) batch.Add(up.uid);
     if (batch.Full || shs.IsLastUid(up.uid)) {
       long[][] nbors = shs.BatchedGetLinks(batch, Dir.Bwd);
       int[] mappedNbors = map.GetMany(Flatten(nbors));
       int q = 0;
       for (int i = 0; i < nbors.Length; i++) {
         for (int j = 0; j < nbors[i].Length; j++) {
           int id = mappedNbors[q++];
           if (id != -1) links[r++] = id;
         }
         pastLast[p++] = r;
       }
       batch.Reset();
     }
       }
       var pam = new long[numVerts];
       p = 0;
       foreach (var up in map.GetAll()) {
     if (up.val != -1) pam[p++] = up.uid;
//.........这里部分代码省略.........
开发者ID:pszmyd,项目名称:SHS,代码行数:101,代码来源:SCC2.cs


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