/// <summary> /// 获取几个集合的交叉并集合 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="operation">Union:并集 Intersect:交集 Difference:差集 详见 <see cref="SetOperation"/></param> /// <param name="keys">要操作的Key集合</param> /// <returns></returns> private async Task <List <T> > _SetCombineAsync <T>(SetOperation operation, params string[] keys) { RedisKey[] keyList = base.ConvertRedisKeysAddSysCustomKey(keys); var rValue = await base.redis.SetCombineAsync(operation, keyList); return(ConvetList <T>(rValue)); }
private int ZSetOperationAndStoreImpl( string destination, SortedSet <ZSetEntry>[] sets, double[] weights, AggregateType aggregateType, SetOperation setOperation) { if (weights != null && weights.Length != sets.Length) { throw new ArgumentException("number of weights must correspond to number of keys", nameof(weights)); } double WeightOf(int idx) => weights?[idx] ?? 1.0; double Aggregator(double a, double b) => aggregateType == AggregateType.Sum ? a + b : aggregateType == AggregateType.Max ? Math.Max(a, b) : Math.Min(a, b); var newSet = new SortedSet <ZSetEntry>( sets.SelectMany((set, idx) => set.Select(e => new ZSetEntry(e.Member, e.Score * WeightOf(idx)))) .GroupBy(e => e.Member) .Where(g => setOperation == SetOperation.Union || g.Count() == sets.Length) .Select(g => new ZSetEntry(g.Key, g.Select(e => e.Score).Aggregate(Aggregator))) ); if (newSet.Count > 0) { _structures[destination] = newSet; } return(newSet.Count); }
public void TestSet() { var operation = new SetOperation<string>(Key, "peep", _vBucket); var buffer = operation.CreateBuffer(); Assert.AreEqual(buffer.Count, 4); IConnection connection = null; try { connection = _connectionPool.Acquire(); SocketError error; connection.Handle.Send(buffer, SocketFlags.None, out error); Assert.AreEqual(SocketError.Success, error); operation.Header = ReadHeader(connection); if (operation.Header.HasData()) { operation.Body = ReadBody(connection, operation.Header); var result = operation.GetResult(); Console.WriteLine(result.Message); } } finally { _connectionPool.Release(connection); } }
/// <summary> /// Evaluates the node asynchronously, using the variables provided in /// the <paramref name="Variables"/> collection. /// </summary> /// <param name="Variables">Variables collection.</param> /// <returns>Result.</returns> public async Task <IElement> EvaluateAsync(Variables Variables) { IDataSource Source = this.source.GetSource(Variables); IResultSetEnumerator e = await Source.Find(0, int.MaxValue, this.where, Variables, new KeyValuePair <VariableReference, bool> [0], this); LinkedList <object> ToUpdate = new LinkedList <object>(); int Count = 0; while (await e.MoveNextAsync()) { if (this.properties is null) { this.properties = new ObjectProperties(e.Current, Variables, false); } else { this.properties.Object = e.Current; } foreach (Assignment SetOperation in this.setOperations) { SetOperation.Evaluate(this.properties); } ToUpdate.AddLast(e.Current); Count++; } await Source.Update(ToUpdate); return(new DoubleNumber(Count)); }
public SetGlobalVariableCommand(string leftExpression, SetOperation operation, string rightExpression, params ParseException[] exceptions) : base(exceptions) { this.leftExpression = leftExpression; this.operation = operation; this.rightExpression = rightExpression; }
public SetOperationCombinedStatement(SqlStatement sqlStatement, SetOperation setOperation) { ArgumentUtility.CheckNotNull("sqlStatement", sqlStatement); _sqlStatement = sqlStatement; _setOperation = setOperation; }
public SetGlobalVariableCommand(string leftExpression, SetOperation operation, string rightExpression) : base() { this.leftExpression = leftExpression; this.operation = operation; this.rightExpression = rightExpression; }
private SetOperation DoIntersection(DictionarySet SetA, DictionarySet SetB) { SetOperation operation2 = new SetOperation(); int num = 0; int num2 = 0; operation2.Changed = false; while ((num < SetA.Count()) & (num2 < SetB.Count())) { if (SetA[num].Key().CompareTo(SetB[num2].Key()) == 0) { MemberResult result = SetA[num].Intersect(SetB[num2]); if (result != null) { operation2.List.Add(result.NewObject); if (result.SetChanged) { operation2.Changed = true; } } num++; num2++; } else if (SetA[num].Key().CompareTo(SetB[num2].Key()) < 0) { num++; } else { num2++; } } operation2.List.RemoveNullItems(); return(operation2); }
public DictionarySet(DictionarySet A, DictionarySet B) { this.MyList = new SortArray(); SetOperation operation = this.DoUnion(A, B); this.MyList = operation.List; }
public void PrepareDisplay() { mAagPrep = new Aag_PrepDisplay(); SetOperation setOp1 = new SetOperation(); setOp1.FireEvent(mAagPrep); // calls Thread 1 method that will fire the event }
/// <summary> /// 获取几个集合的交叉并集合,并保存到一个新Key中 /// </summary> /// <param name="operation">Union:并集 Intersect:交集 Difference:差集 详见 <see cref="SetOperation"/></param> /// <param name="destination">保存的新Key名称</param> /// <param name="keys">要操作的Key集合</param> /// <returns></returns> private async Task <long> _SortedSetCombineAndStoreAsync(SetOperation operation, string destination, params string[] keys) { RedisKey[] keyList = base.ConvertRedisKeys(keys); var rValue = await _conn.GetDatabase(_DefaultDB).SortedSetCombineAndStoreAsync(operation, destination, keyList); return(rValue); }
public void ApplyingFormat() { var state = SetOperation.IterateOnDataSource( null, new[] { 1, 2, 3, 4 }, DictHelper.Create("textformat=C")); Assert.IsNotNull(state); Assert.IsTrue(state is ListDataSourceState); Assert.IsNull(state.TargetSuffix); var iterated = false; var index = 1; foreach (SetItem item in state) { iterated = true; Assert.IsFalse(item.IsSelected); Assert.IsNotNull(item.Text); Assert.IsNotNull(item.Value); Assert.AreEqual(index.ToString("C"), item.Text); Assert.AreEqual(index.ToString(), item.Value); index++; } Assert.IsTrue(iterated); }
private ToolStripMenuItem GetChangeOperationMenuItem(SetOperation operation) { var setOperationMenuItem = new ToolStripMenuItem("Set " + operation, null, (o, args) => SetOperationTo(operation)); switch (operation) { case SetOperation.UNION: setOperationMenuItem.Image = CatalogueIcons.UNION; break; case SetOperation.INTERSECT: setOperationMenuItem.Image = CatalogueIcons.INTERSECT; break; case SetOperation.EXCEPT: setOperationMenuItem.Image = CatalogueIcons.EXCEPT; break; default: throw new ArgumentOutOfRangeException("operation"); } setOperationMenuItem.Enabled = _container.Operation != operation; return(setOperationMenuItem); }
public void MultipleValuesInitialSet_SameTypes() { var state = SetOperation.IterateOnDataSource( new[] { 1, 2 }, new[] { 1, 2, 3, 4 }, null); Assert.IsNotNull(state); Assert.IsTrue(state is SameTypeOperationState); Assert.AreEqual("", state.TargetSuffix); var iterated = false; var index = 1; foreach (SetItem item in state) { iterated = true; if (index == 1 || index == 2) { Assert.IsTrue(item.IsSelected); } else { Assert.IsFalse(item.IsSelected); } Assert.IsNotNull(item.Text); Assert.IsNotNull(item.Value); Assert.AreEqual(index.ToString(), item.Text); Assert.AreEqual(index.ToString(), item.Value); index++; } Assert.IsTrue(iterated); }
public void EmptyInitialSet() { var state = SetOperation.IterateOnDataSource( null, new[] { 1, 2, 3, 4 }, null); Assert.IsNotNull(state); Assert.IsTrue(state is ListDataSourceState); Assert.IsNull(state.TargetSuffix); var iterated = false; var index = 1; foreach (SetItem item in state) { iterated = true; Assert.IsFalse(item.IsSelected); Assert.IsNotNull(item.Text); Assert.IsNotNull(item.Value); Assert.AreEqual(index.ToString(), item.Text); Assert.AreEqual(index.ToString(), item.Value); index++; } Assert.IsTrue(iterated); }
public async Task <long> CombineAndStoreAsync(SetOperation operation, string destination, string[] keys, double[] weights = null, Aggregate aggregate = Aggregate.Sum, CommandFlags flags = CommandFlags.None) { var redisKeys = keys.Select(_ => Wrapper.GetRealKey(_)).ToList(); redisKeys.AddIfNotContains(_realKey); return(await Wrapper.Database.SortedSetCombineAndStoreAsync(operation, Wrapper.GetRealKey(destination), redisKeys.Select(_ => (RedisKey)_).ToArray(), weights, aggregate, flags)); }
/// <summary> /// 比较两个集合并把比较结果存储到目标key /// </summary> /// <param name="operation">比较操作</param> /// <param name="destinationKey">目标key</param> /// <param name="firstKey">第一个</param> /// <param name="secondKey">第二个</param> /// <returns></returns> public static long SortedSetCombineAndStore(SetOperation operation, string destinationKey, string firstKey, string secondKey) { destinationKey = MergeKey(destinationKey); firstKey = MergeKey(firstKey); secondKey = MergeKey(secondKey); return(GetDatabase().SortedSetCombineAndStore(operation, destinationKey, firstKey, secondKey)); }
/// <summary> /// Evaluates the node, using the variables provided in the <paramref name="Variables"/> collection. /// </summary> /// <param name="Variables">Variables collection.</param> /// <returns>Result.</returns> public override IElement Evaluate(Variables Variables) { IElement E = this.source.Evaluate(Variables); if (!(E.AssociatedObjectValue is Type T)) { throw new ScriptRuntimeException("Type expected.", this.source); } IEnumerator e = Select.Find(T, 0, int.MaxValue, this.where, Variables, new string[0], this); LinkedList <object> ToUpdate = new LinkedList <object>(); int Count = 0; while (e.MoveNext()) { ObjectProperties Properties = new ObjectProperties(e.Current, Variables, false); foreach (Assignment SetOperation in this.setOperations) { SetOperation.Evaluate(Properties); } ToUpdate.AddLast(e.Current); Count++; } Database.Update(ToUpdate); return(new DoubleNumber(Count)); }
/// <summary> /// 获取几个集合的交叉并集合,并保存到一个新Key中 /// </summary> /// <param name="operation">Union:并集 Intersect:交集 Difference:差集 详见 <see cref="SetOperation"/></param> /// <param name="destination">保存的新Key名称</param> /// <param name="keys">要操作的Key集合</param> /// <returns></returns> private async Task <long> _SortedSetCombineAndStoreAsync(SetOperation operation, string destination, params string[] keys) { RedisKey[] keyList = ConvertRedisKeysAddSysCustomKey(keys); var rValue = await redis.SortedSetCombineAndStoreAsync(operation, destination, keyList); return(rValue); }
/// <summary> /// 获取几个集合的交叉并集合 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="operation">Union:并集 Intersect:交集 Difference:差集 详见 <see cref="SetOperation"/></param> /// <param name="keys">要操作的Key集合</param> /// <returns></returns> private List <T> _SetCombine <T>(SetOperation operation, params string[] keys) { RedisKey[] keyList = base.ConvertRedisKeysAddSysCustomKey(keys); var rValue = base.redis.SetCombine(operation, keyList); return(ConvetList <T>(rValue)); }
protected SetOperationResultOperatorHandlerBase(SetOperation setOperation, string operationName) { ArgumentUtility.CheckNotNullOrEmpty("operationName", operationName); _setOperation = setOperation; _operationName = operationName; }
public long CombineAndStore(SetOperation operation, string destination, string[] keys, CommandFlags flags = CommandFlags.None) { using (var redis = Server.GetRedisClient(ServerName, true)) { if (operation == SetOperation.Intersect) { //SInterStore redis.StoreIntersectFromSets(destination, keys); } else if (operation == SetOperation.Union) { //SUnionStore redis.StoreUnionFromSets(destination, keys); } else { //SDiffStore string fromSetId = keys[0]; string[] withSetIds = new string[keys.Length - 1]; for (int i = 1; i < keys.Length; i++) { withSetIds[i - 1] = keys[i]; } redis.StoreDifferencesFromSet(destination, fromSetId, withSetIds); } } return(1); }
/// <summary> /// Returns the SQL keyword for the <paramref name="currentContainerOperation"/> /// </summary> /// <param name="currentContainerOperation"></param> /// <param name="dbType"></param> /// <returns></returns> protected virtual string GetSetOperationSql(SetOperation currentContainerOperation, DatabaseType dbType) { if (dbType == DatabaseType.MySql) { throw new NotSupportedException("INTERSECT / UNION / EXCEPT are not supported by MySql caches"); } switch (currentContainerOperation) { case SetOperation.UNION: return("UNION"); case SetOperation.INTERSECT: return("INTERSECT"); case SetOperation.EXCEPT: if (dbType == DatabaseType.Oracle) { return("MINUS"); } return("EXCEPT"); default: throw new ArgumentOutOfRangeException(nameof(currentContainerOperation), currentContainerOperation, null); } }
/// <summary> /// Applies the given <see cref="SetOperation"/>. /// </summary> /// <param name="other">Trait to combine.</param> /// <param name="operation">Set operation.</param> /// <returns>Resulting trait.</returns> public CKTrait Apply(CKTrait other, SetOperation operation) { if (other == null) { throw new ArgumentNullException("other"); } if (operation == SetOperation.Union) { return(Union(other)); } else if (operation == SetOperation.Except) { return(Except(other)); } else if (operation == SetOperation.Intersect) { return(Intersect(other)); } else if (operation == SetOperation.SymetricExcept) { return(SymmetricExcept(other)); } else if (operation == SetOperation.None) { return(this); } Debug.Assert(operation == SetOperation.Replace, "All operations are covered."); return(other); }
public CSGInnerNode(SetOperation op) { switch (op) { case SetOperation.Intersection: bop = (x, y) => x && y; break; case SetOperation.Difference: bop = (x, y) => x && !y; break; case SetOperation.Xor: bop = (x, y) => x ^ y; break; case SetOperation.Union: default: bop = (x, y) => x || y; break; } // set accelerator flags: shortCurcuit = !(bop(false, false) || bop(false, true)); // does empty left operand kill the result? trivial = bop(true, false) && !bop(false, false); // empty right operand doesn't change anything.. }
/// <summary> /// 获取几个集合的交叉并集合 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="operation">Union:并集 Intersect:交集 Difference:差集 详见 <see cref="SetOperation"/></param> /// <param name="keys">要操作的Key集合</param> /// <returns></returns> private async Task <List <T> > _SetCombineAsync <T>(SetOperation operation, params string[] keys) { RedisKey[] keyList = base.ConvertRedisKeys(keys); var rValue = await _conn.GetDatabase(_DefaultDB).SetCombineAsync(operation, keyList); return(ConvetList <T>(rValue)); }
public SetEventData(T data, T previousData, SetOperation operation, int index) { this.value = data; this.previousValue = previousData; this.operation = operation; this.index = index; }
private static IEnumerable <SetOperation <T> > Enumerate([NotNull] IEnumerable <T> items) { foreach (var item in items) { yield return(SetOperation <T> .OnAdd(item)); } }
/// <summary> /// 获取几个集合的交叉并集合,并保存到一个新Key中 /// </summary> /// <param name="db"></param> /// <param name="operation">Union:并集 Intersect:交集 Difference:差集 详见 <see cref="SetOperation"/></param> /// <param name="destination">保存的新Key名称</param> /// <param name="keys">要操作的Key集合</param> /// <returns></returns> private static long _SortedSetCombineAndStore(IDatabase db, SetOperation operation, string destination, params string[] keys) { RedisKey[] keyList = ConvertRedisKeysAddSysCustomKey(keys); var rValue = db.SortedSetCombineAndStore(operation, destination, keyList); return(rValue); }
/// <summary> /// Returns the members of the set resulting from the specified operation against the given sets. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="dbIndex"></param> /// <param name="operation"></param> /// <param name="firstKey"></param> /// <param name="secondKey"></param> /// <returns></returns> public static async Task <string[]> SetCombineAsync(int dbIndex, SetOperation operation, string firstKey, string secondKey) { var db = Instance.GetDatabase(dbIndex); var array = await db.SetCombineAsync(operation, firstKey, secondKey); return(array.ToStringArray()); }
public async Task <T[]> CombineAsync(SetOperation operation, string[] keys, CommandFlags flags = CommandFlags.None) { var redisKeys = keys.Select(k => $"{Wrapper.KeyPrefix}{RedisManager.RedisConfiguration.KeySeparator}{k}").ToList(); redisKeys.AddIfNotContains(_keyName); return(Wrapper.Unwrap <T>(await Wrapper.Database.SetCombineAsync(operation, redisKeys.Select(k => (RedisKey)k).ToArray()))); }
public void Test_SetOperation_Int32() { const string key = "MyInt32"; const int value = 100; const int returnedValueForSet = 0; var operation = new SetOperation<int>(key, value, _vBucket); var operationResult = _ioStrategy.Execute(operation); Assert.IsTrue(operationResult.Success); Assert.AreEqual(operationResult.Status, ResponseStatus.Success); Assert.AreEqual(returnedValueForSet, operationResult.Value); Assert.IsEmpty(operationResult.Message); Console.WriteLine(operationResult.Value); }
protected static CSGInnerNode test6Spheres( SetOperation op ) { // scene: CSGInnerNode root = new CSGInnerNode( op ); Sphere s = new Sphere(); s.SetAttribute( PropertyName.COLOR, new double[] { 1, 0.3, 1 } ); root.InsertChild( s, Matrix4d.Scale( 2 ) ); s = new Sphere(); s.SetAttribute( PropertyName.COLOR, new double[] { 0.5, 0.8, 0.2 } ); root.InsertChild( s, Matrix4d.CreateTranslation( 0, 0, -2 ) ); s = new Sphere(); s.SetAttribute( PropertyName.COLOR, new double[] { 1, 0.3, 0 } ); root.InsertChild( s, Matrix4d.CreateTranslation( 0, 1, -0.5 ) ); s = new Sphere(); s.SetAttribute( PropertyName.COLOR, new double[] { 1, 0.3, 0 } ); root.InsertChild( s, Matrix4d.CreateTranslation( 1, 0, -0.5 ) ); s = new Sphere(); s.SetAttribute( PropertyName.COLOR, new double[] { 1, 0.3, 0 } ); root.InsertChild( s, Matrix4d.CreateTranslation( 0, -1, -0.5 ) ); s = new Sphere(); s.SetAttribute( PropertyName.COLOR, new double[] { 1, 0.3, 0 } ); root.InsertChild( s, Matrix4d.CreateTranslation( -1, 0, -0.5 ) ); return root; }
public CSGInnerNode( SetOperation op ) { switch ( op ) { case SetOperation.Intersection: bop = ( x, y ) => x && y; break; case SetOperation.Difference: bop = ( x, y ) => x && !y; break; case SetOperation.Xor: bop = ( x, y ) => x ^ y; break; case SetOperation.Union: default: bop = ( x, y ) => x || y; break; } // set accelerator flags: shortCurcuit = !(bop( false, false ) || bop( false, true )); // does empty left operand kill the result? trivial = bop( true, false ) && !bop( false, false ); // empty right operand doesn't change anything.. }
public Task<RedisValue[]> CombineAsync(SetOperation operation, RedisKey[] keys, CommandFlags flags = CommandFlags.None) { return RedisAsync.SetCombineAsync(operation, keys, flags); }
protected static CSGInnerNode testWithCylinders( SetOperation op ) { // scene: CSGInnerNode root = new CSGInnerNode( op ); int num = 5; for ( int i = 0; i < num; ++i ) { double j = i; Cylinder c = new Cylinder( -0.5, 0.5 ); c.SetAttribute( PropertyName.COLOR, new double[] { j / num, 1.0 - j / num, 0 } ); root.InsertChild( c, Matrix4d.RotateX( Math.PI / 4 ) * Matrix4d.CreateTranslation( -1 + 0.6 * i, 0, 0 ) ); } return root; }
public Task<long> CombineAndStoreAsync(SetOperation operation, RedisKey destination, RedisKey first, RedisKey second, CommandFlags flags = CommandFlags.None) { return RedisAsync.SetCombineAndStoreAsync(operation, destination, first, second, flags); }
public long CombineAndStore(SetOperation operation, RedisKey destination, RedisKey first, RedisKey second, CommandFlags flags = CommandFlags.None) { return RedisSync.SetCombineAndStore(operation, destination, first, second, flags); }
public Task<long> CombineAndStoreAsync(SetOperation operation, RedisKey destination, RedisKey[] keys, CommandFlags flags = CommandFlags.None) { return RedisAsync.SetCombineAndStoreAsync(operation, destination, keys, flags); }
public long CombineAndStore(SetOperation operation, RedisKey destination, RedisKey[] keys, CommandFlags flags = CommandFlags.None) { return RedisSync.SetCombineAndStore(operation, destination, keys, flags); }
public Task<long> CombineAndStoreAsync(SetOperation operation, RedisKey destination, RedisKey first, RedisKey second, Aggregate aggregate = Aggregate.Sum, CommandFlags flags = CommandFlags.None) { return RedisAsync.SortedSetCombineAndStoreAsync(operation, Key, first, second, aggregate, flags); }
public RedisValue[] Combine(SetOperation operation, RedisKey[] keys, CommandFlags flags = CommandFlags.None) { return RedisSync.SetCombine(operation, keys, flags); }
public Task<RedisValue[]> CombineAsync(SetOperation operation, RedisKey first, RedisKey second, CommandFlags flags = CommandFlags.None) { return RedisAsync.SetCombineAsync(operation, first, second, flags); }
public Task<long> CombineAndStoreAsync(SetOperation operation, RedisKey destination, RedisKey[] keys, double[] weights = null, Aggregate aggregate = Aggregate.Sum, CommandFlags flags = CommandFlags.None) { return RedisAsync.SortedSetCombineAndStoreAsync(operation, Key, keys, weights, aggregate, flags); }
public RedisValue[] Combine(SetOperation operation, RedisKey first, RedisKey second, CommandFlags flags = CommandFlags.None) { return RedisSync.SetCombine(operation, first, second, flags); }
public long CombineAndStore(SetOperation operation, RedisKey first, RedisKey second, Aggregate aggregate = Aggregate.Sum, CommandFlags flags = CommandFlags.None) { return RedisSync.SortedSetCombineAndStore(operation, Key, first, second, aggregate, flags); }