public TrayIcon(string name) { Title = name; stamp = 1; orientation = Orientation.Horizontal; AddEvents ((int)EventMask.PropertyChangeMask); filter = new FilterFunc (ManagerFilter); }
public IEnumerable <TItem> Filter <TItem>(IEnumerable <TItem> list, FilterFunc <TItem, bool> filterFunction) { var result = new List <TItem>(); foreach (var item in list) { var isMatch = filterFunction(item); if (isMatch) { result.Add(item); } } return(result); }
public IEnumerable <string> Filter(IEnumerable <string> list, FilterFunc filterFunction) { var result = new List <string>(); foreach (var item in list) { var isMatch = filterFunction(item); if (isMatch) { result.Add(item); } } return(result); }
public static IEnumerable <HtmlElement> FindAll(this HtmlElement e, FilterFunc f) { if (f(e)) { yield return(e); } foreach (HtmlElement i in e.Children) { foreach (HtmlElement fc in i.FindAll(f)) { yield return(fc); } } }
public void Invoke() { FilterFunc <DummyEntity> createAsyncResult = _ => Rand.Array <DummyEntity>(); var middleware = new SpyFilterMiddlewareToMiddleware(createAsyncResult); Func <DummyContext, Task <FilterFunc <DummyEntity> > > next = _ => Task.FromResult <FilterFunc <DummyEntity> >(__ => Rand.Array <DummyEntity>()); var context = new DummyContext(); new TestCaseRunner() .Run(() => middleware.Invoke(next)(context)) .Verify((actual, desc) => { Assert.AreEqual(createAsyncResult, actual, desc); Assert.AreEqual(context, middleware.ActualContext, desc); Assert.AreEqual(next, middleware.ActualNext, desc); }, (Type)null); }
public void CreateAsync_Cancelled() { FilterFunc <DummyEntity> createResult = _ => Rand.Array <DummyEntity>(); var middleware = new SpyFilterMiddlewareToCreateAsync(createResult, cancelled: true); var context = new DummyContext(); Func <DummyContext, Task <FilterFunc <DummyEntity> > > next = _ => throw new AssertFailedException("next は呼ばれてはいけません。"); new TestCaseRunner() .Run(() => middleware.CreateAsync(context, next)) .Verify((actual, desc) => { Assert.AreEqual(createResult, actual, desc); Assert.AreEqual(context, middleware.ActualContext, desc); Assert.AreEqual(false, middleware.ActualCancelled, desc); }, (Type)null); }
public static HtmlElement Find(this HtmlElement e, FilterFunc f) { if (f(e)) { return(e); } foreach (HtmlElement i in e.Children) { HtmlElement found = i.Find(f); if (found != null) { return(found); } } return(null); }
private void Init() { stamp = 1; orientation = Orientation.Horizontal; AddEvents((int)EventMask.PropertyChangeMask); filter = new FilterFunc(ManagerFilter); Display display = Screen.Display; IntPtr xdisplay = gdk_x11_display_get_xdisplay(display.Handle); selection_atom = XInternAtom(xdisplay, "_NET_SYSTEM_TRAY_S" + Screen.Number.ToString(), false); manager_atom = XInternAtom(xdisplay, "MANAGER", false); system_tray_opcode_atom = XInternAtom(xdisplay, "_NET_SYSTEM_TRAY_OPCODE", false); orientation_atom = XInternAtom(xdisplay, "_NET_SYSTEM_TRAY_ORIENTATION", false); visual_atom = XInternAtom(xdisplay, "_NET_SYSTEM_TRAY_VISUAL", false); message_data_atom = XInternAtom(xdisplay, "_NET_SYSTEM_TRAY_MESSAGE_DATA", false); Screen.RootWindow.AddFilter(filter); UpdateManagerWindow(false); }
private List <TItem> _filterData(string search = "") { if (Options != null) { _isDataTouched = false; if (FilterFunc != null) { return(FilterFunc?.Invoke(_options, search).ToList()); } else { return(_internalFilter(search)); } } else { _isDataTouched = false; return(new List <TItem>()); } }
public void CreateAsync_NullNextFunc() { FilterFunc <DummyEntity> createResult = _ => Rand.Array <DummyEntity>(); var middleware = new SpyFilterMiddlewareToCreateAsync(createResult, cancelled: false); var context = new DummyContext(); DummyContext actualNextContext = default; Func <DummyContext, Task <FilterFunc <DummyEntity> > > next = ctx => { actualNextContext = ctx; return(Task.FromResult(SpyFilterMiddlewareToCreateAsync.NullFilter)); }; new TestCaseRunner() .Run(() => middleware.CreateAsync(context, next)) .Verify((actual, desc) => { Assert.AreEqual(createResult, actual, desc); Assert.AreEqual(context, middleware.ActualContext, desc); Assert.AreEqual(false, middleware.ActualCancelled, desc); Assert.AreEqual(context, actualNextContext, desc); }, (Type)null); }
public void Invoke_NullPredicate() { var predicateCreator = new SpyPredicateCreator(PredicateMiddleware <DummyContext, DummyEntity> .NullPredicate); var middleware = new PredicateFilterMiddleware <DummyContext, DummyEntity>(predicateCreator.Invoke); var context = new DummyContext(); FilterFunc <DummyEntity> nextFilter = _ => Rand.Array <DummyEntity>(); DummyContext actualNextContext = default; Func <DummyContext, Task <FilterFunc <DummyEntity> > > next = ctx => { actualNextContext = ctx; return(Task.FromResult(nextFilter)); }; new TestCaseRunner() .Run(() => middleware.Invoke(next)(context)) .Verify((actual, desc) => { Assert.AreEqual(nextFilter, actual, desc); Assert.AreEqual(context, predicateCreator.ActualContext, desc); Assert.AreEqual(context, actualNextContext, desc); }, (Type)null); }
public FindTemplate(Wrappers.Node grp, FilterFunc func, Gtk.Window parent) : base("Find Template", parent, DialogFlags.DestroyWithParent | DialogFlags.NoSeparator) { d_tree = new Widgets.WrappersTree(grp); d_tree.RendererToggle.Visible = false; d_tree.Show(); if (func != null) { d_tree.Filter += delegate(Widgets.WrappersTree.WrapperNode node, ref bool ret) { if (node.Wrapper == null) { ret = false; } else { ret &= func(node.Wrapper); } }; } d_tree.Activated += delegate(object source, Widgets.WrappersTree.WrapperNode[] wrappers) { Respond(ResponseType.Apply); }; d_tree.TreeView.Selection.SelectFunction = CantSelectImports; VBox.PackStart(d_tree, true, true, 0); TransientFor = parent; AddButton(Gtk.Stock.Close, ResponseType.Close); AddButton(Gtk.Stock.Apply, ResponseType.Apply); d_tree.Entry.GrabFocus(); SetDefaultSize(400, 300); }
/// <summary> /// <see cref="IMiddleware{T, TResult}.Invoke(Func{T, TResult})"/> の実装。 /// </summary> public Func <TContext, Task <FilterFunc <TEntity> > > Invoke(Func <TContext, Task <FilterFunc <TEntity> > > next) { Debug.Assert(next != null); return(async context => { Debug.Assert(context != null); PredicateFunc <TEntity> predicate = await _predicateCreator(context).ConfigureAwait(false); Debug.Assert(predicate != null); FilterFunc <TEntity> nextFilter = await next(context).ConfigureAwait(false); Debug.Assert(nextFilter != null); if (predicate == PredicateMiddleware <TContext, TEntity> .NullPredicate) { return nextFilter; } var predicateFunc = new Func <TEntity, bool>(predicate); return source => nextFilter(source.Where(predicateFunc)); }); }
public void Filter(FilterFunc func) { bool checkme = true; List <Node> children = new List <Node>(d_children); foreach (Node child in children) { child.Filter(func); if (child.Visible) { checkme = false; } } if (checkme && d_parent != null && func != null) { Visible = func(this); } else { Visible = true; } }
/// <summary> /// Filter all nodes in project recursively. Returns list of nodes, for which the filter function returned True. /// </summary> /// <param name="filterFunc">User-defined function for filtering</param> /// <returns>Node list</returns> public List<MyNode> Filter(FilterFunc filterFunc) { List<MyNode> nodes = new List<MyNode>(); MyNodeGroup.IteratorAction a = x => { if (x.GetType() != typeof(MyNodeGroup) && filterFunc(x)) { nodes.Add(x); } }; Project.Network.Iterate(true, a); return nodes; }
public void RemoveFilter (FilterFunc function) { var hash = Data ["filter_func_hash"] as Dictionary<FilterFunc, GdkSharp.FilterFuncWrapper>; GdkSharp.FilterFuncWrapper wrapper = null; if (hash.TryGetValue (function, out wrapper)) { hash.Remove (function); gdk_window_remove_filter (Handle, wrapper.NativeDelegate, IntPtr.Zero); } }
public void AddFilter (FilterFunc function) { if (!Data.ContainsKey ("filter_func_hash")) { Data ["filter_func_hash"] = new Dictionary<FilterFunc, GdkSharp.FilterFuncWrapper> (); } var hash = Data ["filter_func_hash"] as Dictionary<FilterFunc, GdkSharp.FilterFuncWrapper>; GdkSharp.FilterFuncWrapper wrapper = new GdkSharp.FilterFuncWrapper (function); hash [function] = wrapper; gdk_window_add_filter (Handle, wrapper.NativeDelegate, IntPtr.Zero); }
public static void RemoveFilterForAll(FilterFunc func) { GdkSharp.FilterFuncWrapper wrapper = FilterAllHash [func] as GdkSharp.FilterFuncWrapper; if (wrapper == null) return; FilterAllHash.Remove (func); gdk_window_remove_filter (IntPtr.Zero, wrapper.NativeDelegate, IntPtr.Zero); }
public static HtmlElement Find(this HtmlElement e, FilterFunc f) { if (f(e)) { return e; } foreach (HtmlElement i in e.Children) { HtmlElement found = i.Find(f); if (found != null) { return found; } } return null; }
public static void Register(FilterIdentifier identifier, string name, FilterFunc filterFunc) { var registration = new H5FilterRegistration(identifier, name, filterFunc); H5Filter.Registrations.Add(registration); }
public ManagedJobList ReInitialize(DiscoDataContext Database, FilterFunc FilterFunction, SortFunc SortFunction, bool FilterAuthorization) { if (Database == null) throw new ArgumentNullException("Database"); lock (updateLock) { if (FilterFunction != null) this.FilterFunction = FilterFunction; if (SortFunction != null) this.SortFunction = SortFunction; base.Items = this.SortFunction(this.DetermineItems(Database, this.FilterFunction(Database.Jobs), FilterAuthorization)).ToList(); } return this; }
public void AddFilter(FilterFunc function) { if (!Data.Contains ("filter_func_hash")) Data ["filter_func_hash"] = new Hashtable (); Hashtable hash = Data ["filter_func_hash"] as Hashtable; GdkSharp.FilterFuncWrapper wrapper = new GdkSharp.FilterFuncWrapper (function); hash [function] = wrapper; gdk_window_add_filter (Handle, wrapper.NativeDelegate, IntPtr.Zero); }
public int Select(IList <Server> configs, int curIndex, BalanceType algorithm, FilterFunc filter, bool forceChange = false) { lastSelectIndex = SubSelect(configs, curIndex, algorithm, filter, forceChange); if (lastSelectIndex >= 0 && lastSelectIndex < configs.Count) { lastSelectID = configs[lastSelectIndex].Id; } else { lastSelectID = null; } return(lastSelectIndex); }
private void Init () { stamp = 1; orientation = Orientation.Horizontal; AddEvents ((int)EventMask.PropertyChangeMask); filter = new FilterFunc (ManagerFilter); Display display = Screen.Display; IntPtr xdisplay = gdk_x11_display_get_xdisplay (display.Handle); selection_atom = XInternAtom (xdisplay, "_NET_SYSTEM_TRAY_S" + Screen.Number.ToString (), false); manager_atom = XInternAtom (xdisplay, "MANAGER", false); system_tray_opcode_atom = XInternAtom (xdisplay, "_NET_SYSTEM_TRAY_OPCODE", false); orientation_atom = XInternAtom (xdisplay, "_NET_SYSTEM_TRAY_ORIENTATION", false); visual_atom = XInternAtom (xdisplay, "_NET_SYSTEM_TRAY_VISUAL", false); message_data_atom = XInternAtom (xdisplay, "_NET_SYSTEM_TRAY_MESSAGE_DATA", false); Screen.RootWindow.AddFilter (filter); UpdateManagerWindow (false); }
public SpyFilterMiddlewareToCreateAsync(FilterFunc <DummyEntity> createResult, bool cancelled) { _createResult = createResult; _cancelled = cancelled; }
public SpyFilterMiddlewareToMiddleware(FilterFunc <DummyEntity> createAsyncResult) => _createAsyncResult = createAsyncResult;
public new void Filter(FilterFunc func) { base.Filter(func); d_lastFilter = func; }
public ManagedJobList(string Name, FilterFunc FilterFunction, SortFunc SortFunction) { this.Name = Name; this.FilterFunction = FilterFunction; this.SortFunction = SortFunction; }
public static void AddFilterForAll(FilterFunc func) { GdkSharp.FilterFuncWrapper wrapper = new GdkSharp.FilterFuncWrapper(func); FilterAllHash [func] = wrapper; gdk_window_add_filter(IntPtr.Zero, wrapper.NativeDelegate, IntPtr.Zero); }
public ManagedJobList ReInitialize(DiscoDataContext Database, FilterFunc FilterFunction, bool FilterAuthorization) { return ReInitialize(Database, FilterFunction, null, FilterAuthorization); }
public static IEnumerable<HtmlElement> FindAll(this HtmlElement e, FilterFunc f) { if (f(e)) { yield return e; } foreach (HtmlElement i in e.Children) { foreach (HtmlElement fc in i.FindAll(f)) { yield return fc; } } }
private void Init () { stamp = 1; //orientation = Orientation.Horizontal; AddEvents ((int)EventMask.PropertyChangeMask); filter = new FilterFunc (ManagerFilter); }
public void RemoveFilter(FilterFunc function) { Hashtable hash = Data ["filter_func_hash"] as Hashtable; GdkSharp.FilterFuncWrapper wrapper = hash [function] as GdkSharp.FilterFuncWrapper; if (wrapper == null) return; hash.Remove (function); gdk_window_remove_filter (Handle, wrapper.NativeDelegate, IntPtr.Zero); }
public H5FilterRegistration(FilterIdentifier identifier, string name, FilterFunc filterFunc) { this.Identifier = identifier; this.Name = name; this.FilterFunc = filterFunc; }
public Filter() { FilterToApply = RequestBypass; Reset(); }
private unsafe string GetImage(string imageName, out int channels, FilterFunc filter = null) { if (_processedEntries.TryGetValue(imageName, out var existing)) { using var img = new MagickImage(); img.Ping(existing); channels = img.ChannelCount; return(existing); } try { var tempPath = Path.GetTempFileName(); _tempFiles.Add(tempPath); var fullPath = Path.Combine(_texturePath, imageName + ".dds"); if (!File.Exists(fullPath)) { channels = 0; _processedEntries[imageName] = null; return(null); } // Console.WriteLine($"Converting {imageName}..."); using var surface = Pfim.Pfim.FromFile(fullPath); surface.Decompress(); int width = surface.Width; int height = surface.Height; int offset = 0; int length = surface.DataLen; var data = new byte[length]; Array.Copy(surface.Data, offset, data, 0, length); var mat = new Mat(); // Console.WriteLine(imageName + " - " + surface.Format); if (surface.Format == ImageFormat.Rgb24) { mat = new Mat(height, width, MatType.CV_8UC3, data); channels = 3; if (filter != null) { mat.ForEachAsVec3b((p, pos) => { // We marshal a Vec3b as Vec4b which is dangerous filter(ref Unsafe.AsRef <Vec4b>(p)); }); } } else if (surface.Format == ImageFormat.Rgba32) { mat = new Mat(height, width, MatType.CV_8UC4, data); channels = 4; // if (filter != null) { mat.ForEachAsVec4b((p, pos) => { filter(ref Unsafe.AsRef <Vec4b>(p)); }); } } else { throw new Exception($"Unsupported format {imageName}: {surface.Format}"); } using var fileStream = File.OpenWrite(tempPath); // mat.ImWrite(imageName + ".png"); mat.WriteToStream(fileStream); _processedEntries[imageName] = tempPath; mat.Dispose(); return(tempPath); } catch (Exception e) { Console.Error.WriteLine(e); _processedEntries[imageName] = null; channels = 0; return(null); } }
public static void AddFilterForAll (FilterFunc func) { GdkSharp.FilterFuncWrapper wrapper = new GdkSharp.FilterFuncWrapper (func); FilterAllHash [func] = wrapper; gdk_window_add_filter (IntPtr.Zero, wrapper.NativeDelegate, IntPtr.Zero); }
public int Select(List <Server> configs, int curIndex, int algorithm, FilterFunc filter, bool forceChange = false) { if (randomGennarator == null) { randomGennarator = new Random(); lastSelectIndex = -1; } if (configs.Count <= lastSelectIndex || lastSelectIndex < 0 || !configs[lastSelectIndex].isEnable()) { lastSelectIndex = -1; lastSelectTime = DateTime.Now; lastUserSelectIndex = -1; } if (lastUserSelectIndex != curIndex) { if (configs.Count > curIndex && curIndex >= 0 && configs[curIndex].isEnable()) { lastSelectIndex = curIndex; } lastUserSelectIndex = curIndex; } if (configs.Count > 0) { List <ServerIndex> serverList = new List <ServerIndex>(); for (int i = 0; i < configs.Count; ++i) { if (forceChange && lastSelectIndex == i) { continue; } if (configs[i].isEnable()) { if (filter != null) { if (!filter(configs[i], lastSelectIndex < 0 ? null : configs[lastSelectIndex])) { continue; } } serverList.Add(new ServerIndex(i, configs[i])); } } if (forceChange && serverList.Count > 1) { for (int i = 0; i < serverList.Count; ++i) { if (serverList[i].index == lastSelectIndex) { serverList.RemoveAt(i); break; } } } if (serverList.Count == 0) { int i = lastSelectIndex; if (i >= 0 && i < configs.Count && configs[i].isEnable()) { serverList.Add(new ServerIndex(i, configs[i])); } } int serverListIndex = -1; if (serverList.Count > 0) { if (algorithm == (int)SelectAlgorithm.OneByOne) { int selIndex = -1; for (int i = 0; i < serverList.Count; ++i) { if (serverList[i].index == lastSelectIndex) { selIndex = i; break; } } if (selIndex != -1) { serverListIndex = serverList[(selIndex + 1) % serverList.Count].index; } else { serverListIndex = serverList[0].index; } } else if (algorithm == (int)SelectAlgorithm.Random) { serverListIndex = randomGennarator.Next(serverList.Count); serverListIndex = serverList[serverListIndex].index; } else if (algorithm == (int)SelectAlgorithm.LowException || algorithm == (int)SelectAlgorithm.Timer) { if (algorithm == (int)SelectAlgorithm.Timer) { if ((DateTime.Now - lastSelectTime).TotalSeconds > 60 * 10) { lastSelectTime = DateTime.Now; } else { if (configs.Count > lastSelectIndex && lastSelectIndex >= 0 && configs[lastSelectIndex].isEnable() && !forceChange) { return(lastSelectIndex); } } } List <double> chances = new List <double>(); double lastBeginVal = 0; foreach (ServerIndex s in serverList) { double chance = Algorithm3(s.server.ServerSpeedLog()); if (chance > 0) { chances.Add(lastBeginVal + chance); lastBeginVal += chance; } } { double target = randomGennarator.NextDouble() * lastBeginVal; serverListIndex = lowerBound(chances, target); serverListIndex = serverList[serverListIndex].index; lastSelectIndex = serverListIndex; return(serverListIndex); } } else //if (algorithm == (int)SelectAlgorithm.LowLatency || algorithm == (int)SelectAlgorithm.SelectedFirst) { List <double> chances = new List <double>(); double lastBeginVal = 0; foreach (ServerIndex s in serverList) { double chance = Algorithm2(s.server.ServerSpeedLog()); if (chance > 0) { chances.Add(lastBeginVal + chance); lastBeginVal += chance; } } if (algorithm == (int)SelectAlgorithm.SelectedFirst && randomGennarator.Next(3) == 0 && configs[curIndex].isEnable()) { for (int i = 0; i < serverList.Count; ++i) { if (curIndex == serverList[i].index) { lastSelectIndex = curIndex; return(curIndex); } } } { double target = randomGennarator.NextDouble() * lastBeginVal; serverListIndex = lowerBound(chances, target); serverListIndex = serverList[serverListIndex].index; lastSelectIndex = serverListIndex; return(serverListIndex); } } } lastSelectIndex = serverListIndex; return(serverListIndex); } else { return(-1); } }
public static void RemoveFilterForAll (FilterFunc func) { GdkSharp.FilterFuncWrapper wrapper = null; if (FilterAllHash.TryGetValue (func, out wrapper)) { FilterAllHash.Remove (func); gdk_window_remove_filter (IntPtr.Zero, wrapper.NativeDelegate, IntPtr.Zero); } }
protected int SubSelect(IList <Server> configs, int curIndex, BalanceType algorithm, FilterFunc filter, bool forceChange) { if (randomGennarator == null) { randomGennarator = new Random(); lastSelectIndex = -1; } if (configs.Count <= lastSelectIndex || lastSelectIndex < 0) { lastSelectIndex = -1; lastSelectTime = DateTime.Now; lastUserSelectIndex = -1; } else { if (configs[lastSelectIndex].Id != lastSelectID) { if (lastSelectID != null) { for (var i = 0; i < configs.Count; ++i) { if (configs[i].Id == lastSelectID) { lastSelectIndex = i; break; } } } if (configs[lastSelectIndex].Id != lastSelectID) { lastSelectIndex = -1; lastSelectTime = DateTime.Now; lastUserSelectIndex = -1; } } } if (lastUserSelectIndex != curIndex) { if (configs.Count > curIndex && curIndex >= 0 && algorithm != BalanceType.Timer) { lastSelectIndex = curIndex; } lastUserSelectIndex = curIndex; } if (lastSelectIndex == -1) { if (configs.Count > curIndex && curIndex >= 0) { lastSelectIndex = curIndex; } } if (configs.Count > 0) { var serverList = new List <ServerIndex>(); for (var i = 0; i < configs.Count; ++i) { if (configs[i].Enable) { if (filter != null) { if (!filter(configs[i], lastSelectIndex < 0 ? null : configs[lastSelectIndex])) { continue; } } serverList.Add(new ServerIndex(i, configs[i])); } } if (serverList.Count == 0 && filter != null) { for (var i = 0; i < configs.Count; ++i) { if (!filter(configs[i], lastSelectIndex < 0 ? null : configs[lastSelectIndex])) { continue; } serverList.Add(new ServerIndex(i, configs[i])); } } if (forceChange && serverList.Count > 1 && algorithm != BalanceType.OneByOne) { for (var i = 0; i < serverList.Count; ++i) { if (serverList[i].index == lastSelectIndex) { serverList.RemoveAt(i); break; } } } if (serverList.Count == 0) { var i = lastSelectIndex; if (i >= 0 && i < configs.Count && configs[i].Enable) { serverList.Add(new ServerIndex(i, configs[i])); } } var serverListIndex = -1; if (serverList.Count > 0) { if (algorithm == BalanceType.OneByOne) { var selIndex = -1; for (var i = 0; i < serverList.Count; ++i) { if (serverList[i].index == lastSelectIndex) { selIndex = i; break; } } serverListIndex = serverList[(selIndex + 1) % serverList.Count].index; } else if (algorithm == BalanceType.Random) { serverListIndex = randomGennarator.Next(serverList.Count); serverListIndex = serverList[serverListIndex].index; } else if (algorithm == BalanceType.LowException || algorithm == BalanceType.Timer || algorithm == BalanceType.FastDownloadSpeed) { if (algorithm == BalanceType.Timer) { if ((DateTime.Now - lastSelectTime).TotalSeconds > 60 * 5) { lastSelectTime = DateTime.Now; } else { if (configs.Count > lastSelectIndex && lastSelectIndex >= 0 && configs[lastSelectIndex].Enable && !forceChange) { return(lastSelectIndex); } } } var chances = new List <double>(); double lastBeginVal = 0; if (algorithm == BalanceType.FastDownloadSpeed) { long avg_speed = 1024 * 64; long sum_speed = 0; var sum_cnt = 0; var zero_cnt = 0; foreach (var s in serverList) { s.server.SpeedLog.GetTransSpeed(out _, out var speed_d); if (speed_d == 0) { ++zero_cnt; } else { sum_speed += speed_d; ++sum_cnt; } } var zero_chance = 0.5; if (sum_cnt > 0) { avg_speed = sum_speed / sum_cnt; if (zero_cnt + sum_cnt > 0) { zero_chance = 0.1 * sum_cnt / (zero_cnt + sum_cnt); } } foreach (var s in serverList) { var chance = Algorithm4(s.server.SpeedLog, avg_speed, zero_chance); if (chance > 0) { chances.Add(lastBeginVal + chance); lastBeginVal += chance; } } } else { foreach (var s in serverList) { var chance = Algorithm3(s.server.SpeedLog); if (chance > 0) { chances.Add(lastBeginVal + chance); lastBeginVal += chance; } } } { var target = randomGennarator.NextDouble() * lastBeginVal; serverListIndex = lowerBound(chances, target); serverListIndex = serverList[serverListIndex].index; return(serverListIndex); } } else //if (algorithm == (int)SelectAlgorithm.LowLatency || algorithm == (int)SelectAlgorithm.SelectedFirst) { var chances = new List <double>(); double lastBeginVal = 0; foreach (var s in serverList) { var chance = Algorithm2(s.server.SpeedLog); if (chance > 0) { chances.Add(lastBeginVal + chance); lastBeginVal += chance; } } if (algorithm == BalanceType.SelectedFirst && randomGennarator.Next(3) == 0 && configs[curIndex].Enable) { for (var i = 0; i < serverList.Count; ++i) { if (curIndex == serverList[i].index) { return(curIndex); } } } { var target = randomGennarator.NextDouble() * lastBeginVal; serverListIndex = lowerBound(chances, target); serverListIndex = serverList[serverListIndex].index; return(serverListIndex); } } } return(serverListIndex); } return(-1); }
public int Select(ObservableCollection <Server> configs, int curIndex, string algorithm, FilterFunc filter, bool forceChange = false) { lastSelectIndex = SubSelect(configs, curIndex, algorithm, filter, forceChange); if (lastSelectIndex >= 0 && lastSelectIndex < configs.Count) { lastSelectID = configs[lastSelectIndex].Id; } else { lastSelectID = null; } return(lastSelectIndex); }
public static void Register(H5FilterID identifier, string name, FilterFunc filterFunc) { var registration = new H5FilterRegistration((FilterIdentifier)identifier, name, filterFunc); H5Filter.Registrations.AddOrUpdate((FilterIdentifier)identifier, registration, (_, registration) => registration); }
public FilterDelegates(string name, FilterFunc filter) { Filter = filter; Name = name; }