• Avalanche.Core
Search Results for

    Show / Hide Table of Contents
    • Avalanche.Accessor
      • Introduction
      • IAccessor
        • IAccessor
        • IListAccessor
        • IMapAccessor
        • IRecordAccessor
        • IContentAccessor
        • IOneOfAccessor
        • IAnyAccessor
      • .Net
        • Introduction
        • IList<T>
        • IDictionary<K,V>
        • FieldInfo
        • OneOfAttribute
        • StructLayoutAttribute
        • Class
      • Protobuf
        • Introduction
      • Articles
        • Dependency Injection
        • AccessorMessages
    • Avalanche.Binding
      • Introduction
    • Avalanche.Configuration
      • Introduction
      • Configuration Binding
      • ConfigurationExtensions
      • MemoryConfiguration
      • PrintTree
      • Saving IOptions
      • Yaml
    • Avalanche.Converter
      • Introduction
      • EnumConverter
      • Func<,>
      • HexConverter
      • PrimitiveConverter
      • StringConverter
    • Avalanche.Core
      • License
    • Avalanche.DataType
      • Introduction
      • DataType
        • IDataType
        • IListType
        • IMapType
        • IRecordType
        • IFieldType
        • IOneOfType
        • IAnyType
        • IStringType
        • IValueType
        • IIntegerType
        • IEnumerationType
        • IRealType
      • .Net
        • Introduction
        • IList<T>
        • IDictionary<K,V>
        • FieldInfo
        • Enum
        • OneOfAttribute
        • StructLayoutAttribute
        • Class
      • Protobuf
        • Introduction
      • Articles
        • DataTypeRequest
        • PrintTree
        • DataTypeMessages
    • Avalanche.Emit
      • Introduction
      • TypeBuilder
      • ConstructorBuilder
      • MethodBuilder
      • PropertyBuilder
      • FieldBuilder
      • Emit
      • Utilities
    • Avalanche.FileSystem
      • Introduction
      • Abstractions
        • IFileSystem
          • IFileSystemBrowse
          • IFileSystemCreateDirectory
          • IFileSystemDelete
          • IFileSystemFileAttribute
          • IFileSystemMount
          • IFileSystemMove
          • IFileSystemObserve
          • IFileSystemOpen
        • IEvent
        • IEntry
        • IOption
        • IToken
      • FileSystem
      • VirtualFileSystem
      • MemoryFileSystem
      • EmbeddedFileSystem
      • HttpFileSystem
      • Decoration
      • IFileProvider
      • Events
      • Utilities
        • Dispose
        • File Scanner
        • Visit Tree
        • File Operation
        • FilterEnumerable
        • PollingFilterWatchToken
    • Avalanche.Identity
      • Introduction
      • Identity
      • IdentityParts
      • IdentityInterner
      • IdentityComparer
      • Print Tree
      • IdentityAccessors
        • Introduction
        • TypeName
    • Avalanche.Localization
      • Introduction
      • Localization
      • LocalizationFile
      • LocalizationFiles
      • LocalizationFileSystem
      • LocalizationFileFormat
      • LocalizationLine
      • LocalizationLines
      • TemplateFormat
      • CultureProvider
      • FallbackCultureProvider
      • ResourceManager
      • LocalizationError
      • Microsoft.Extensions
        • Introduction
        • DependencyInjection
        • FileProvider
        • Logging
        • ITextLocalizer
        • IFileLocalizer
        • Localization
      • Asp.Net
        • Introduction
        • Supplying localization
        • Inject to pages
        • Culture Assigned
        • Minimalistic Api
        • Diagnostics
      • Pluralization
        • Introduction
        • Multiple plural parameters
        • Custom PluralRules
        • Invariant Culture
        • Unit Prefix
        • IPluralRule
        • IPluralNumber
        • IPluralRules
        • CLDRs
        • Unicode.CLDR40
        • Unicode.CLDR41
        • Unicode.CLDR42
      • Articles
        • Alphabet localization
        • Benchmarks
        • Caching
        • Class Library
        • Demo
        • Diagnostics
        • Embedded resources
        • Emplacement
        • File localization
        • Text localization
        • Printing templates
    • Avalanche.Message
      • Introduction
      • IMessage
      • IMessageProvider
      • IMessageDescription
      • IMessageDescriptions
      • MessageLevel
      • Message printing
      • Messages and Exceptions
      • Microsoft.Extensions
        • DependencyInjection
      • Articles
        • Aggregate Messages
        • Localization
        • Logging
        • Validation
    • Avalanche.Options
      • Introduction
      • OptionsExtensions
      • OptionsMonitorCast
    • Avalanche.Service
      • Introduction
      • Service
        • Introduction
        • IService
        • IServiceDisposable
        • IServiceDecoration
        • IServiceCast
        • IServiceObservable
        • IServiceContainer
        • Construction
        • Query
        • CancellationToken
        • CachePolicy
        • Scope
      • Handler
        • Introduction
        • IHandler
        • IHandlerCast
        • IHandlerDecoration
        • IHandlerWithOrder
        • CancellationToken
        • Cyclicity
        • Delegates
        • Invokable
        • ExportAttribute
        • OrderAttribute
        • PrintTree
        • Recursion
      • Query
        • Introduction
        • IQuery
        • IQueryCast
        • IQueryDecoration
      • Entry
        • Introduction
        • IEntry
        • IEntryCast
        • IEntryDecoration
        • IEntryObservable
        • IEntryVisitable
        • EntryState
      • Request
        • Introduction
        • IRequest
        • IRequestFor
        • IRequestToBeCached
        • IRequestToBeDisposed
        • RequestAttribute
        • ContextParameterAttribute
        • Print Tree
      • Dependency Injection
        • Introduction
        • Asp.Net
        • ServiceRequest<T>
        • Decorating a service
        • Handler
        • CachePolicy
        • CancellationToken
        • QueryLogger
        • IHostBuilder
      • Examples
        • NodeCount
        • Expression
        • Mapper
      • Articles
        • Benchmarks
        • Error Handling
        • ServiceMessages
    • Avalanche.StatusCode
      • Introduction
      • HResult
        • Introduction
        • HResult.Facilities
        • BasicMessages
        • RpcMessages
        • DispatchMessages
        • StorageMessages
        • ItfMessages
        • Win32Messages
        • WindowsMessages
        • SspiMessages
        • CertMessages
        • MediaServerMessages
        • SetupApiMessages
        • ScardMessages
        • ComPlusMessages
        • ClrMessages
        • UserModeFilterManagerMessages
        • GraphicsMessages
        • TpmServicesMessages
        • TpmSoftwareMessages
        • PlaMessages
        • FveMessages
        • FwpMessages
        • NdisMessages
        • DltMessages
      • System
        • Introduction
        • AccessControlMessages
        • AggregateMessages
        • AppDomainMessages
        • ArgumentMessages
        • ArgumentNullMessages
        • ArgumentOutOfRangeMessages
        • ArithmeticMessages
        • ArrayMessages
        • AssemblyMessages
        • BadImageFormatMessages
        • CodeContractMessages
        • CodePageMessages
        • CollectionsMessages
        • CompilerServiceMessages
        • CryptographyMessages
        • CultureMessages
        • DiagnosticsMessages
        • EventSourceMessages
        • ExecutionEngineMessages
        • FormatMessages
        • HostProtectionMessages
        • IOMessages
        • IndexOutOfRangeMessages
        • InteropServiceMessages
        • InvalidCastMessages
        • InvalidOperationMessages
        • IsolatedStorageMessages
        • LazyMessages
        • MarshalerMessages
        • MemoryMessages
        • MiscellaneousMessages
        • NotImplementedMessages
        • NotSupportedMessages
        • ObjectDisposedMessages
        • OperationCanceledMessages
        • OverflowMessages
        • PlatformMessages
        • PolicyMessages
        • PrincipalMessages
        • ProgramMessages
        • ReferenceMessages
        • ReflectionMessages
        • RegionMessages
        • RemotingMessages
        • ResourcesMessages
        • SecurityMessages
        • SerializationMessages
        • StackMessages
        • TaskMessages
        • TextMessages
        • ThreadingMessages
        • TimeZoneMessages
        • TypeMessages
        • XmlMessages
      • HttpStatusCode
      • OpcUaStatusCode
    • Avalanche.Template
      • Introduction
      • TemplateFormats
      • ITemplatePrintable
      • ITemplateFormatPrintable
      • ITemplateText
      • ITemplateBreakdown
      • ITemplateFormat
      • ITemplateFormats
      • Extract Arguments
      • Emplacement
    • Avalanche.Tokenizer
      • Introduction
      • IToken
      • ITokenizer
      • Tokenizers
    • Avalanche.Utilities
      • Introduction
      • Collections
        • Tuples
        • StructList
        • ArrayList
        • BijectionMap
        • LocakableDictionary
        • LockableList
        • MapList
        • Pipe
        • RingQueue
        • EnumerableExtensions
        • TupleUtilities
        • ArrayUtilities
      • Comparers
        • IGraphComparer
        • IGraphComparable
        • AlphaNumericComparer
        • EnumerableComparer
        • EnumerableGraphComparer
        • ReferenceComparer
        • KeyValuePairComparer
        • DefaultComparerProvider
        • RecordComparer
      • Cloners
        • ICloner
        • IGraphCloner
        • IGraphCloneable
        • ListCloner
        • DictionaryCloner
        • FieldCloner
        • PassthroughCloner
        • RecordCloner
        • ClonerProvider
      • Dispose
        • IDisposeAttachable
        • IDisposeBelatable
      • Provider
        • Introduction
        • ProviderBase
        • Delegate
        • Pipe
        • Cache
        • ResultCapture
        • AsReadOnly
        • AsService
        • IProviderEvent
      • Record
        • IRecordDescription
        • IFieldDescription
        • IConstructorDescription
        • IConstructionDescription
        • IParameterDescription
        • IRecordProviders
        • RecordDelegates
          • RecordCreate
          • RecordClone
          • RecordCopy
          • IRecordDelegates
        • FieldDelegates
          • FieldRead
          • FieldWrite
          • RecreateWith
          • IFieldDelegates
      • Reflection
        • EnumDescription
      • String
        • IEscaper
        • UnicodeString
        • Hex
      • Miscellaneous
        • IIdGenerator
        • Permutation
        • IReadOnly
        • IUserDataContainer
        • ITreeNode
        • Void
    • Avalanche.Writer
      • Introduction
      • ConstantWriter
      • Context
      • ConvertWriter
      • DefaultConstructor
      • DelegateWriter
      • PassthroughWriter
      • Referer
      • TypeCast
      • Writer
      • WriterPipe
      • WriterMessages

    Tuples

    Tuples are not entirely trivial. There is variance in the features that are needed in different situations. In this package there are tuples that come from the permutations of the following features.

    Value-Typed and Reference-Typed

    There are value-typed struct versions and reference-typed class versions of each tuple. Reference-typed tuples have suffix Object, for example "PairObject".

    // Stack allocated
    var pair_stack = new Pair<int, int>(1, 2);
    
    // Heap allocated
    var pair_heap = new PairObject<int, int>(1, 2);
    

    Mutability

    Tuples that are mutable have suffix Mutable. Immutable tuples don't have a suffix. Immutable tuples cache their hashcode, and mutable calculate as needed.

    // Immutable
    var pair_immutable = new Pair<int, int>(1, 2);
    int hash_is_cached = pair_immutable.GetHashCode();
    
    // Mutable
    var pair_mutable = new PairMutable<int, int>(2, 3);
    pair_mutable.a = 4;
    pair_mutable.b = 6;
    int hash_is_calculated = pair_mutable.GetHashCode();
    

    Set Tuples

    The elements of set tuples are interchangeable, the order of elements doesn't matter in hash-equals comparisons. That means that PairSet(1, 2) is equal to PairSet(2, 1). The name suffix is "Set", for example "PairSet".

    // Create pairs
    var pair1 = new PairSet<int>(1, 2);
    var pair2 = new PairSet<int>(2, 1);
    
    // Get equality comparer singleton instance
    IEqualityComparer<PairSet<int>> equalsComparer = PairSet<int>.EqualityComparer.Instance;
    
    // Compare
    bool areEqual = equalsComparer.Equals(pair1, pair2);
    

    EqualityComparer

    Each tuple class comes with an EqualityComparer implementation. There is a singleton instance TupleType.EqualityComparer.Instance.

    // Create pairs
    var pair1 = new Pair<int, int>(1, 2);
    var pair2 = new Pair<int, int>(2, 3);
    
    // Get equality comparer singleton instance
    IEqualityComparer<Pair<int, int>> equalsComparer = Pair<int, int>.EqualityComparer.Instance;
    
    // Compare
    bool areEqual = equalsComparer.Equals(pair1, pair2);
    

    Tuple types implement IEquatable<TupleType> any way, so they comparable as is. This makes value typed tuples comparable without boxing.

    // Compare
    bool areEqual = pair1.Equals(pair2);
    

    Comparer

    Each non-Set tuple class comes with a Comparer implementation. There is a singleton instance TupleType.Comparer.Instance.

    // Create pairs
    var pair1 = new Pair<int, int>(1, 2);
    var pair2 = new Pair<int, int>(2, 3);
    
    // Get equality comparer singleton instance
    IComparer<Pair<int, int>> comparer = Pair<int, int>.Comparer.Instance;
    
    // Compare
    int c = comparer.Compare(pair1, pair2);
    

    Tuple types implement IComparable<TupleType> any way, so they comparable as is. This makes value typed tuples comparable without boxing.

    // Compare
    int c = pair1.CompareTo(pair2);
    

    Argument Count

    There is a separate tuple type for cases with different number of arguments. The stem of the name is based on the count.

    1. Container
    2. Pair
    3. Triple
    4. Quad
    5. Pento
    6. Sextim
    7. Septim
    8. Octet
    // One argument
    var container = new ContainerMutableObject<string>("Hello");
    container.a = "New Hello";
    
    // Two arguments
    var pair = new PairMutable<int, int>(1, 2);
    
    // Three arguments
    var triple = new TripleSet<int>(5, 6, 7);
    
    // Four arguments
    var quad = new QuadObject<byte, byte, byte, byte>(1, 2, 3, 4);
    

    Classes

    Name Type Hashcode Mutability Elements Ordered
    Container<A> struct cached immutable are ordered
    ContainerObject<A> class cached immutable are ordered
    ContainerMutable<A> struct not cached mutable are ordered
    ContainerMutableObject<A> class not cached mutable are ordered
    Pair<A, B> struct cached immutable are ordered
    PairObject<A, B> class cached immutable are ordered
    PairMutable<A, B> struct not cached mutable are ordered
    PairMutableObject<A, B> class not cached mutable are ordered
    PairSet<T> struct cached immutable are interchangeable
    PairSetObject<T> class cached immutable are interchangeable
    PairSetMutable<T> struct not cached mutable are interchangeable
    PairSetMutableObject<T> class not cached mutable are interchangeable
    Triple<A, B, C> struct cached immutable are ordered
    TripleObject<A, B, C> class cached immutable are ordered
    TripleMutable<A, B, C> struct not cached mutable are ordered
    TripleMutableObject<A, B, C> class not cached mutable are ordered
    TripleSet<T> struct cached immutable are interchangeable
    TripleSetObject<T> class cached immutable are interchangeable
    TripleSetMutable<T> struct not cached mutable are interchangeable
    TripleSetMutableObject<T> class not cached mutable are interchangeable
    Quad<A, B, C, D> struct cached immutable are ordered
    QuadObject<A, B, C, D> class cached immutable are ordered
    QuadMutable<A, B, C, D> struct not cached mutable are ordered
    QuadMutableObject<A, B, C, D> class not cached mutable are ordered
    QuadSet<T> struct cached immutable are interchangeable
    QuadSetObject<T> class cached immutable are interchangeable
    QuadSetMutable<T> struct not cached mutable are interchangeable
    QuadSetMutableObject<T> class not cached mutable are interchangeable
    Pento<A, B, C, D, E> struct cached immutable are ordered
    PentoObject<A, B, C, D, E> class cached immutable are ordered
    PentoMutable<A, B, C, D, E> struct not cached mutable are ordered
    PentoMutableObject<A, B, C, D, E> class not cached mutable are ordered
    Sextim<A, B, C, D, E, F> struct cached immutable are ordered
    SextimObject<A, B, C, D, E, F> class cached immutable are ordered
    SextimMutable<A, B, C, D, E, F> struct not cached mutable are ordered
    SextimMutableObject<A, B, C, D, E, F> class not cached mutable are ordered
    Septim<A, B, C, D, E, F, G> struct cached immutable are ordered
    SeptimObject<A, B, C, D, E, F, G> class cached immutable are ordered
    SeptimMutable<A, B, C, D, E, F, G> struct not cached mutable are ordered
    SeptimMutableObject<A, B, C, D, E, F, G> class not cached mutable are ordered
    Octet<A, B, C, D, E, F, G, H> struct cached immutable are ordered
    OctetObject<A, B, C, D, E, F, G, H> class cached immutable are ordered
    OctetMutable<A, B, C, D, E, F, G, H> struct not cached mutable are ordered
    OctetMutableObject<A, B, C, D, E, F, G, H> class not cached mutable are ordered
    In This Article
    Back to top Copyright © Toni Kalajainen