void GeneratePrimes() { primeNumberDisplay.Children.Clear(); ISieve sieve = SieveFactory.GetSieve(SieveType.Turner); ulong min = Convert.ToUInt32(min_TextBox.Text); ulong max = Convert.ToUInt32(max_TextBox.Text); Prime p; do { p = sieve.NextPrime(); }while (p < min); string currentMinText = min_TextBox.Text; string currentMaxText = max_TextBox.Text; string result = string.Join(",", new string[] { currentMinText, currentMaxText }); //set a breakpoint here for (ulong i = min; i <= max; ++i) { Ellipse e = new Ellipse(); e.Height = 10; e.Width = 10; e.Fill = new SolidColorBrush(Color.FromArgb(255, 255, 200, 105)); if (i == p) { e.Fill = new SolidColorBrush(Color.FromArgb(255, 44, 89, 64)); p = sieve.NextPrime(); } primeNumberDisplay.Children.Add(e); } }
void Test(ISieve sieve, long expectedCount, long expectedSum, long expectedHash) { long count = 0, sum = 0, hash = 0; Action <long> action = (p) => { count++; sum += p; hash = hash * 31 + p; }; sieve.ListPrimes(action); Assert.AreEqual(expectedCount, count); Assert.AreEqual(expectedSum, sum); Assert.AreEqual(expectedHash, hash); }
public CachedFactorizer(ISieve sieve, IFactorizer factorizer) { Sieve = sieve; Factorizer = factorizer; _memory.Add(2); _memory.Add(3); _memory.Add(5); _memory.Add(7); _fullySeached = 7; }
static void TestSieve <T>(long length, long expectedCount, long expectedSum, long expectedHash) { var sw = Stopwatch.StartNew(); ISieve sieve = CreateSieve <T>(length); long count = 0, sum = 0, hash = 0; Action <long> action = (p) => { count++; sum += p; hash = hash * 31 + p; }; sieve.ListPrimes(action); AssertEquals(expectedCount, count); AssertEquals(expectedSum, sum); AssertEquals(expectedHash, hash); Console.WriteLine($"{typeof(T).Name} up to {length:N0} in {sw.Elapsed}"); }
public static IWorker wrap(ISieve sieve) { IList<Property> props = new List<Property>(); foreach( Identifier name in sieve.visibleScidentreNames ) props.Add(new Property(name, false, new NType())); IInterface face = new Interface( new IInterface[]{}, new Callee[]{}, new Breeder[]{}, props, new Method[]{}); NObject o = new NObject(); WorkerBuilder b = new WorkerBuilder(face, o, new IWorker[]{}); foreach( Identifier name in sieve.visibleScidentreNames ) { //The same 'name' variable is used through each iteration. //If the delegate refers to 'name', it will always get the value that 'name' refered to last. Identifier name2 = name; b.addPropertyGetter( name, delegate() { return GE.evalIdent(sieve, name2); }); } return b.compile(); }
static void buildStandardLibrary(Node_Module node) { IScope scope = new Scope(null, new ScopeAllowance(false,false)); ScopeQueue sq = new ScopeQueue(); Sieve sieve = Executor.executeGetSieve(node.sieve, sq, scope); _stdSieve = sieve; GE.declareAssign( new Identifier("Interface"), ScidentreCategory.CONSTANT, new NType(), stdn_Interface.worker, sieve.visible ); GE.declareAssign( new Identifier("Object"), ScidentreCategory.CONSTANT, new NType(), stdn_Object.worker, sieve.visible ); GE.declareAssign( new Identifier("any"), ScidentreCategory.CONSTANT, new NType(), stdn_Object.worker, //xxx temporary - won't work when type checking is enabled sieve.visible ); sq.executeAll(); GE.declareAssign( new Identifier("true"), ScidentreCategory.CONSTANT, new NType(stdn_Bool), Client_Boolean.wrap(true), sieve.visible ); GE.declareAssign( new Identifier("false"), ScidentreCategory.CONSTANT, new NType(stdn_Bool), Client_Boolean.wrap(false), sieve.visible ); _std = LibraryWrapper.wrap(_stdSieve); }
void Test <T>(long length, long expectedCount, long expectedSum, long expectedHash) where T : ISieve { ISieve t = CreateSieve <T>(length); Test(t, expectedCount, expectedSum, expectedHash); }
public static IWorker evalIdent(ISieve d, string name) { return evalIdent(d, new Identifier(name)); }
public static IWorker evalIdent(ISieve d, Identifier name) { DerefResults results = d.deref(name); if( results.worker != null ) return results.worker; if( results.workerList != null ) { if( results.workerList.Count > 1 ) throw new NotImplementedException(); return results.workerList[0]; } throw new ClientException( String.Format("scidentre '{0}' not found", name)); }