1+ using StringEnricher . Nodes . Shared ;
2+
3+ namespace StringEnricher . Configuration ;
4+
5+ /// <summary>
6+ /// Configuration settings for a node.
7+ /// </summary>
8+ public struct NodeSettings
9+ {
10+ /// <summary>
11+ /// The name of the node.
12+ /// </summary>
13+ public string Name { get ; }
14+
15+ /// <summary>
16+ /// The buffer sizes to use for the node.
17+ /// </summary>
18+ private BufferSizes _bufferSizes ;
19+
20+ /// <summary>
21+ /// The buffer allocation thresholds to use for the node.
22+ /// </summary>
23+ private BufferAllocationThresholds _bufferAllocationThresholds ;
24+
25+ /// <summary>
26+ /// Initializes a new instance of the <see cref="NodeSettings"/> struct.
27+ /// </summary>
28+ public NodeSettings (
29+ string name ,
30+ BufferSizes bufferSizes ,
31+ BufferAllocationThresholds bufferAllocationThresholds
32+ )
33+ {
34+ Name = name ;
35+ _bufferSizes = bufferSizes ;
36+ _bufferAllocationThresholds = bufferAllocationThresholds ;
37+ }
38+
39+ /// <summary>
40+ /// Initializes a new instance of the <see cref="NodeSettings"/> struct.
41+ /// </summary>
42+ /// <param name="name">The name of the node.</param>
43+ /// <param name="initialBufferLength">
44+ /// The initial length of the buffer to be used for memory allocation.
45+ /// This value must be greater than zero and less than or equal to <paramref name="maxBufferLength"/>.
46+ /// </param>
47+ /// <param name="maxBufferLength">
48+ /// The maximum length of the buffer to be used for memory allocation when the initial buffer is insufficient.
49+ /// This value must be greater than zero and greater than or equal to <paramref name="initialBufferLength"/>.
50+ /// </param>
51+ /// <param name="growthFactor">
52+ /// The growth factor to use when increasing buffer sizes.
53+ /// This factor determines how quickly the buffer size increases when the initial buffer is insufficient.
54+ /// Must be greater than 1.0.
55+ /// </param>
56+ /// <param name="maxStackAllocLength">
57+ /// The maximum length of the buffer to be allocated on the stack.
58+ /// If a buffer larger than this is needed, memory won't be allocated on the stack.
59+ /// If a buffer smaller than or equal to this is needed, it will be allocated on the stack.
60+ ///
61+ /// Note: Dual-threshold memory model: two adjustable boundaries define how objects are allocated — to the stack,
62+ /// array pool, or heap. Shifting the thresholds dynamically redistributes memory ranges between these regions
63+ /// for optimal performance and balance.
64+ ///
65+ /// |-----------|----------------------|--------------------------->
66+ /// ^ ^ ^
67+ /// 0 MaxStackAllocLength MaxPooledArrayLength
68+ ///
69+ /// [0, MaxStackAllocLength) -> Stack allocation
70+ /// [MaxStackAllocLength, MaxPooledArrayLength) -> Array Pool
71+ /// [MaxPooledArrayLength, ∞) -> Heap allocation
72+ /// </param>
73+ /// <param name="maxPooledArrayLength">
74+ /// The maximum length of the buffer to be allocated from the array pool.
75+ /// If a buffer larger than this is needed, a new array will be allocated instead of renting from the pool.
76+ /// If a buffer smaller than or equal to this is needed, it will be rented from the pool.
77+ ///
78+ /// Note: Dual-threshold memory model: two adjustable boundaries define how objects are allocated — to the stack,
79+ /// array pool, or heap. Shifting the thresholds dynamically redistributes memory ranges between these regions
80+ /// for optimal performance and balance.
81+ ///
82+ /// |-----------|----------------------|--------------------------->
83+ /// ^ ^ ^
84+ /// 0 MaxStackAllocLength MaxPooledArrayLength
85+ ///
86+ /// [0, MaxStackAllocLength) -> Stack allocation
87+ /// [MaxStackAllocLength, MaxPooledArrayLength) -> Array Pool
88+ /// [MaxPooledArrayLength, ∞) -> Heap allocation
89+ /// </param>
90+ public NodeSettings (
91+ string name ,
92+ int initialBufferLength ,
93+ int maxBufferLength ,
94+ float growthFactor ,
95+ int maxStackAllocLength ,
96+ int maxPooledArrayLength
97+ ) : this (
98+ name ,
99+ new BufferSizes ( name , initialBufferLength , maxBufferLength , growthFactor ) ,
100+ new BufferAllocationThresholds ( name , maxStackAllocLength , maxPooledArrayLength )
101+ )
102+ {
103+ }
104+
105+ /// <summary>
106+ /// The multiplier to use when resizing the buffer for formatting a <see cref="DateOnlyNode"/>.
107+ /// When the current buffer is insufficient, it will be resized by multiplying its size by this factor.
108+ /// Default is 2.0 (doubling the buffer size).
109+ /// Note: A higher multiplier reduces the number of resizing operations but may lead to increased memory usage.
110+ /// A lower multiplier minimizes memory usage but may increase the number of resizing operations, impacting performance.
111+ /// Recommended range is between 1.5 and 3.0.
112+ /// </summary>
113+ public float GrowthFactor
114+ {
115+ get => _bufferSizes . GrowthFactor ;
116+ set => _bufferSizes . GrowthFactor = value ;
117+ }
118+
119+ /// <summary>
120+ /// The initial buffer length to use when formatting a <see cref="DateOnlyNode"/>.
121+ /// This buffer is used to attempt formatting the node before falling back to larger buffers.
122+ /// </summary>
123+ public int InitialBufferSize
124+ {
125+ get => _bufferSizes . InitialBufferLength ;
126+ set => _bufferSizes . InitialBufferLength = value ;
127+ }
128+
129+ /// <summary>
130+ /// The maximum buffer length to use when formatting a <see cref="DateOnlyNode"/>.
131+ /// If formatting requires a buffer larger than this, an exception will be thrown.
132+ /// </summary>
133+ public int MaxBufferSize
134+ {
135+ get => _bufferSizes . MaxBufferLength ;
136+ set => _bufferSizes . MaxBufferLength = value ;
137+ }
138+
139+ /// <summary>
140+ /// The maximum length of a buffer that can be allocated on the stack when formatting a <see cref="DateOnlyNode"/>.
141+ /// Buffers larger than this will be allocated on the heap.
142+ /// </summary>
143+ public int MaxStackAllocLength
144+ {
145+ get => _bufferAllocationThresholds . MaxStackAllocLength ;
146+ set => _bufferAllocationThresholds . MaxStackAllocLength = value ;
147+ }
148+
149+ /// <summary>
150+ /// The maximum length of a buffer that can be rented from the array pool when formatting a <see cref="DateOnlyNode"/>.
151+ /// Buffers larger than this will be allocated on the heap.
152+ /// </summary>
153+ public int MaxPooledArrayLength
154+ {
155+ get => _bufferAllocationThresholds . MaxPooledArrayLength ;
156+ set => _bufferAllocationThresholds . MaxPooledArrayLength = value ;
157+ }
158+ }
0 commit comments