Generators

Namespace: NHibernate
We found 10 examples in language CSharp for this search. You will see 31 fragments of code.

Other methods


		/// <summary>
		/// Метод возвращает данные генератора по его индексу
		/// </summary>
		/// <param name="Index">Индекс генератора</param>
		/// <returns>Данные генератора</returns>
		public CGData GetGeneratorData (int Index)
			{
			if ((Index >= 1) && (Index <= generators.Count))
				return generators[Index - 1];
			else
				return null;
			}

		/// <summary>
		/// Метод устанавливает новые данные для генератора по его индексу
		/// </summary>
		/// <param name="Index">Индекс генератора</param>
		/// <param name="Data">Данные генератора</param>
		public void SetGeneratorData (int Index, CGData Data)
			{
			if ((Index >= 1) && (Index <= generators.Count))
				generators[Index - 1] = new CGData (Data);
			}


        /// <summary>
        /// Resets the generators to the defaults
        /// </summary>
        /// <param name="Random">Random object</param>
        /// <returns>The random object sent in</returns>
        public static System.Random ResetGenerators(this System.Random Random)
        {
            Generators = null;
            SetupGenerators();
            return Random;
        }


        /// <summary>
        /// Resets the generators to the defaults
        /// </summary>
        /// <param name="Random">Random object</param>
        /// <returns>The random object sent in</returns>
        public static System.Random ResetGenerators(this System.Random Random)
        {
            Generators = null;
            SetupGenerators();
            return Random;
        }

		
		/// <summary>
		/// Initialization method called by the package base class when this package is loaded.
		/// </summary>
		protected override void Initialize()
		{
			base.Initialize();

			// Register the editor factory used to create the DSL editor.
			this.RegisterEditorFactory(new GeneratorLanguageEditorFactory(this));
			
			// Initialize the toolbox helper
			toolboxHelper = new global::Ultramarine.Generators.Language.GeneratorLanguageToolboxHelper(this);

			// Create the command set that handles menu commands provided by this package.
			GeneratorLanguageCommandSet commandSet = new GeneratorLanguageCommandSet(this);
			commandSet.Initialize();
			
			// Create the command set that handles cut/copy/paste commands provided by this package.
			GeneratorLanguageClipboardCommandSet clipboardCommandSet = new GeneratorLanguageClipboardCommandSet(this);
			clipboardCommandSet.Initialize();
			
			// Register the model explorer tool window for this DSL.
			this.AddToolWindow(typeof(GeneratorLanguageExplorerToolWindow));

			// Initialize Extension Registars
			// this is a partial method call
			this.InitializeExtensions();

			// Add dynamic toolbox items
			this.SetupDynamicToolbox();
		}
		
		/// <summary>
		/// Returns any dynamic tool items for the designer
		/// </summary>
		/// <remarks>The default implementation is to return the list of items from the generated toolbox helper.</remarks>
		protected override global::System.Collections.Generic.IList<DslDesign::ModelingToolboxItem> CreateToolboxItems()
		{
			try
			{
				Debug.Assert(toolboxHelper != null, "Toolbox helper is not initialized");
				return toolboxHelper.CreateToolboxItems();
			}
			catch(global::System.Exception e)
			{
				global::System.Diagnostics.Debug.Fail("Exception thrown during toolbox item creation.  This may result in Package Load Failure:\r\n\r\n" + e);
				throw;
			}
		}
		
		
		/// <summary>
		/// Given a toolbox item "unique ID" and a data format identifier, returns the content of
		/// the data format. 
		/// </summary>
		/// <param name="itemId">The unique ToolboxItem to retrieve data for</param>
		/// <param name="format">The desired format of the resulting data</param>
		protected override object GetToolboxItemData(string itemId, DataFormats.Format format)
		{
			Debug.Assert(toolboxHelper != null, "Toolbox helper is not initialized");
		
			// Retrieve the specified ToolboxItem from the DSL
			return toolboxHelper.GetToolboxItemData(itemId, format);
		}


        /// <summary>
        /// Checks to make sure that all parameters are set, and that
        /// Generators is an array of at least two.
        /// </summary>
        /// <returns></returns>
        public bool Verify()
        {
            if ((this.Group == null)
                || (this.HashFunctionName == null)
                || (this.Generators.Length < 2))
            {
                return false;
            }
            return true;
        }

        /// <summary>
        /// Serialize generators.
        /// </summary>
        /// <param name="context"></param>
        [OnSerializing]
        internal void OnSerializing(StreamingContext context)
        {
            _generators = CryptoSerializer.SerializeGroupElementArray(this.Generators, "Generators");
        }

        /// <summary>
        /// Deserialize generators.
        /// </summary>
        public override void FinishDeserializing()
        {
            this.Generators = CryptoSerializer.DeserializeGroupElementArray(_generators, "Generators", this.Group);
        }


        protected override void ReadData(DataBuffer buf, FileFormat fmt)
        {
            int size = SaveFileGTA3VC.ReadBlockHeader(buf, "CGN");

            int infoSize = buf.ReadInt32();
            Debug.Assert(infoSize == CarGeneratorDataSize);
            NumberOfCarGenerators = buf.ReadInt32();
            NumberOfEnabledCarGenerators = buf.ReadInt32();
            ProcessCounter = buf.ReadByte();
            GenerateEvenIfPlayerIsCloseCounter = buf.ReadByte();
            buf.ReadInt16();
            int carGensSize = buf.ReadInt32();
            Debug.Assert(carGensSize == CarGeneratorArraySize);
            CarGenerators = buf.ReadArray<CarGenerator>(MaxNumCarGenerators);

            Debug.Assert(buf.Offset == GetSize(fmt));
            Debug.Assert(size == GetSize(fmt) - SaveFileGTA3VC.BlockHeaderSize);
        }

        protected override void WriteData(DataBuffer buf, FileFormat fmt)
        {
            SaveFileGTA3VC.WriteBlockHeader(buf, "CGN", SizeOfType<CarGeneratorData>() - SaveFileGTA3VC.BlockHeaderSize);

            buf.Write(CarGeneratorDataSize);
            buf.Write(NumberOfCarGenerators);
            buf.Write(NumberOfEnabledCarGenerators);
            buf.Write(ProcessCounter);
            buf.Write(GenerateEvenIfPlayerIsCloseCounter);
            buf.Write((short) 0);
            buf.Write(CarGeneratorArraySize);
            buf.Write(CarGenerators, MaxNumCarGenerators);

            Debug.Assert(buf.Offset == GetSize(fmt));
        }

        protected override int GetSize(FileFormat fmt)
        {
            return 0x1FE8;
        }

        public override bool Equals(object obj)
        {
            return Equals(obj as CarGeneratorData);
        }

        public bool Equals(CarGeneratorData other)
        {
            if (other == null)
            {
                return false;
            }

            return NumberOfCarGenerators.Equals(other.NumberOfCarGenerators)
                && NumberOfEnabledCarGenerators.Equals(other.NumberOfEnabledCarGenerators)
                && ProcessCounter.Equals(other.ProcessCounter)
                && GenerateEvenIfPlayerIsCloseCounter.Equals(other.GenerateEvenIfPlayerIsCloseCounter)
                && CarGenerators.SequenceEqual(other.CarGenerators);
        }

        public CarGeneratorData DeepClone()
        {
            return new CarGeneratorData(this);
        }

        public int[] find(int p)
        {
            List<int> generators = new List<int>();

            for(int i = 2; i < p; i++)
            {
                bool[] elements = new bool[p - 1];
                int n = 1;

                for (int j = 0; j < p - 1; j++)
                {
                    elements[n % p - 1] = true;
                    n = (n * i) % p;
                }

                if (elements.All(b => b))
                    generators.Add(i);
            }

            return generators.ToArray();
        }
        [TestMethod]
        public void GeneratorsTest()
        {
            GeneratorsTestClass.GeneratorsTest(3, new int[] { 2 });
            GeneratorsTestClass.GeneratorsTest(5, new int[] { 2, 3 });
            GeneratorsTestClass.GeneratorsTest(13, new int[] { 2, 6, 7, 11 });
            GeneratorsTestClass.GeneratorsTest(19, new int[] { 2, 3, 10, 13, 14, 15 });
            GeneratorsTestClass.GeneratorsTest(337, new int[]
            {
                10, 15, 19, 20, 22, 23, 29, 31, 33, 34, 44, 45, 46, 51, 53, 60, 61, 67, 68,
                70, 71, 73, 80, 83, 87, 89, 90, 93, 99, 101, 106, 109, 114, 116, 118,
                120, 124, 130, 132, 134, 139, 143, 151, 152, 154, 160, 161, 166, 171,
                176, 177, 183, 185, 186, 194, 198, 203, 205, 207, 213, 217, 219, 221,
                223, 228, 231, 236, 238, 244, 247, 248, 250, 254, 257, 264, 266, 267,
                269, 270, 276, 277, 284, 286, 291, 292, 293, 303, 304, 306, 308, 314,
                315, 317, 318, 322, 327
            });
        }

        private static void GeneratorsTest(int p, int[] expected)
        {
            Generators generators = new Generators();
            int[] results = generators.find(p);
            Assert.AreEqual(expected.Length, results.Length);
            for (int i = 0; i < results.Length; i++)
                Assert.AreEqual(expected[i], results[i]);
        }


        static string joinCodeGenerators(string[] codeGenerators) {
            return string.Join(",",
                                codeGenerators
                                    .Where(generator => !string.IsNullOrEmpty(generator))
                                    .ToArray()
                            ).Replace(" ", string.Empty);
        }

        public override string ToString() {
            return _config.ToString();
        }


        protected override void ReadData(DataBuffer buf, FileFormat fmt)
        {
            int size = SaveFileGTA3VC.ReadBlockHeader(buf, "CGN");

            int infoSize = buf.ReadInt32();
            Debug.Assert(infoSize == CarGeneratorDataSize);
            NumberOfCarGenerators = buf.ReadInt32();
            NumberOfEnabledCarGenerators = buf.ReadInt32();
            ProcessCounter = buf.ReadByte();
            GenerateEvenIfPlayerIsCloseCounter = buf.ReadByte();
            buf.ReadInt16();
            int carGensSize = buf.ReadInt32();
            Debug.Assert(carGensSize == CarGeneratorArraySize);
            CarGenerators = buf.ReadArray<CarGenerator>(MaxNumCarGenerators);

            Debug.Assert(buf.Offset == SizeOfType<CarGeneratorData>());
            Debug.Assert(size == SizeOfType<CarGeneratorData>() - SaveFileGTA3VC.BlockHeaderSize);
        }

        protected override void WriteData(DataBuffer buf, FileFormat fmt)
        {
            SaveFileGTA3VC.WriteBlockHeader(buf, "CGN", SizeOfType<CarGeneratorData>() - SaveFileGTA3VC.BlockHeaderSize);

            buf.Write(CarGeneratorDataSize);
            buf.Write(NumberOfCarGenerators);
            buf.Write(NumberOfEnabledCarGenerators);
            buf.Write(ProcessCounter);
            buf.Write(GenerateEvenIfPlayerIsCloseCounter);
            buf.Write((short) 0);
            buf.Write(CarGeneratorArraySize);
            buf.Write(CarGenerators, MaxNumCarGenerators);

            Debug.Assert(buf.Offset == SizeOfType<CarGeneratorData>());
        }

        protected override int GetSize(FileFormat fmt)
        {
            return 0x2D1C;
        }

        public override bool Equals(object obj)
        {
            return Equals(obj as CarGeneratorData);
        }

        public bool Equals(CarGeneratorData other)
        {
            if (other == null)
            {
                return false;
            }

            return NumberOfCarGenerators.Equals(other.NumberOfCarGenerators)
                && NumberOfEnabledCarGenerators.Equals(other.NumberOfEnabledCarGenerators)
                && ProcessCounter.Equals(other.ProcessCounter)
                && GenerateEvenIfPlayerIsCloseCounter.Equals(other.GenerateEvenIfPlayerIsCloseCounter)
                && CarGenerators.SequenceEqual(other.CarGenerators);
        }

        public CarGeneratorData DeepClone()
        {
            return new CarGeneratorData(this);
        }


        protected override void AppendGenerators(int decisionId, IList<Generator> generators)
        {
            if (!_decisionGenerators.ContainsKey(decisionId))
            {
                _decisionGenerators.Add(decisionId, new DecisionGenerators());
            }

            var decisionGenerators = _decisionGenerators[decisionId];

            foreach (var generator in generators)
            {
                RemoveSupergenerators(generator, decisionGenerators);
            }

            foreach (var generator in generators)
            {
                AppendGenerator(generator, decisionGenerators);
            }
        }

        private void RemoveSupergenerators(Generator subgenerator, DecisionGenerators decisionGenerators)
        {
            var invertedList = decisionGenerators.InvertedList;

            if (!invertedList.ContainsKey(subgenerator[0]))
            {
                return;
            }

            // Find supergenerators
            IList<long> supergenerators = new List<long>(invertedList[subgenerator[0]].Keys);

            for (int i = 1; i < subgenerator.Count; i++)
            {
                SortedList<long, bool> itemGenerators;

                if (!invertedList.TryGetValue(subgenerator[i], out itemGenerators))
                {
                    return;
                }

                supergenerators = supergenerators.SortedIntersect(itemGenerators.Keys);

                if (supergenerators.Count == 0)
                {
                    return;
                }
            }

            // Remove supergenerators
            foreach (var supergenerator in supergenerators)
            {
                decisionGenerators.Generators.Remove(supergenerator);

                foreach (var generators in invertedList)
                {
                    generators.Value.Remove(supergenerator);
                }
            }
        }

        private void AppendGenerator(Generator generator, DecisionGenerators decisionGenerators)
        {
            decisionGenerators.Generators.Add(generator.GetIdentifier(), generator);

            var invertedList = decisionGenerators.InvertedList;

            foreach (var item in generator)
            {
                if (!invertedList.ContainsKey(item))
                {
                    invertedList.Add(item, new SortedList<long, bool> { { generator.GetIdentifier(), false } });
                }
                else
                {
                    invertedList[item].Add(generator.GetIdentifier(), false );
                }
            }
        }

        public override IDictionary<int, IList<Generator>> GetDecisionsGenerators()
        {
            var result = new Dictionary<int, IList<Generator>>();

            foreach (var decisionInvertedList in _decisionGenerators)
            {
                result.Add(decisionInvertedList.Key, decisionInvertedList.Value.Generators.Values.ToList());
            }

            return result;
        }

NHibernate.Mapping.ByCode.Generators : Object

Methods :

public static IGeneratorDef get_Assigned()
public static IGeneratorDef get_Native()
public static IGeneratorDef get_HighLow()
public static IGeneratorDef get_Guid()
public static IGeneratorDef get_GuidComb()
public static IGeneratorDef get_Sequence()
public static IGeneratorDef get_Identity()
public static IGeneratorDef get_EnhancedSequence()
public static IGeneratorDef get_EnhancedTable()
public static IGeneratorDef get_Counter()
public static IGeneratorDef get_Increment()
public static IGeneratorDef get_NativeGuid()
public static IGeneratorDef get_Select()
public static IGeneratorDef get_SequenceHiLo()
public static IGeneratorDef get_Table()
public static IGeneratorDef get_TriggerIdentity()
public static IGeneratorDef get_SequenceIdentity()
public static IGeneratorDef UUIDHex()
public static IGeneratorDef UUIDHex(String format = )
public static IGeneratorDef UUIDHex(String format = , String separator = )
public static IGeneratorDef get_UUIDString()
public static IGeneratorDef Foreign(Expression<Func<TEntity, Object>> property = )
public static IGeneratorDef Foreign(MemberInfo property = )
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()