本文整理汇总了C#中Service.IsLastUid方法的典型用法代码示例。如果您正苦于以下问题:C# Service.IsLastUid方法的具体用法?C# Service.IsLastUid怎么用?C# Service.IsLastUid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Service
的用法示例。
在下文中一共展示了Service.IsLastUid方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: 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);
}
}
示例3: 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);
}
}
示例4: 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;
//.........这里部分代码省略.........