Skip to content

Commit bbda347

Browse files
authored
Merge (#119) - UIntXL (work in progress)
2 parents 9871204 + b4884ed commit bbda347

File tree

68 files changed

+9094
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+9094
-8
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"configurations" : [
3+
{
4+
"id" : "2BBD9A51-D890-4B97-AED4-B9962867DF57",
5+
"name" : "Main",
6+
"options" : {
7+
8+
}
9+
}
10+
],
11+
"defaultOptions" : {
12+
"codeCoverage" : false
13+
},
14+
"testTargets" : [
15+
{
16+
"skippedTests" : [
17+
"NBKFibonacciXLBenchmarks\/testNoLoop10000000()",
18+
"NBKFlexibleWidthBenchmarksOnExponentiationAsUIntXL\/test7RaisedToPrime777()",
19+
"NBKFlexibleWidthBenchmarksOnExponentiationAsUIntXL\/testNoLoop5RaisedToPrime22222()",
20+
"NBKFlexibleWidthBenchmarksOnExponentiationAsUIntXL\/testNoLoop5RaisedToPrime33333()",
21+
"NBKFlexibleWidthBenchmarksOnExponentiationAsUIntXL\/testNoLoop5RaisedToPrime55555()",
22+
"NBKFlexibleWidthBenchmarksOnExponentiationAsUIntXL\/testNoLoop7RaisedToPrime77777()",
23+
"NBKFlexibleWidthBenchmarksOnTextAsUIntXL\/testEncodingUsingSwiftStdlibRadix10()",
24+
"NBKFlexibleWidthBenchmarksOnTextAsUIntXL\/testEncodingUsingSwiftStdlibRadix16()"
25+
],
26+
"target" : {
27+
"containerPath" : "container:",
28+
"identifier" : "NBKFlexibleWidthKitBenchmarks",
29+
"name" : "NBKFlexibleWidthKitBenchmarks"
30+
}
31+
}
32+
],
33+
"version" : 1
34+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"configurations" : [
3+
{
4+
"id" : "6FC9897F-2BF3-4836-8372-787CE5195F87",
5+
"name" : "Main",
6+
"options" : {
7+
8+
}
9+
}
10+
],
11+
"defaultOptions" : {
12+
"codeCoverage" : {
13+
"targets" : [
14+
{
15+
"containerPath" : "container:",
16+
"identifier" : "NBKFlexibleWidthKit",
17+
"name" : "NBKFlexibleWidthKit"
18+
}
19+
]
20+
}
21+
},
22+
"testTargets" : [
23+
{
24+
"target" : {
25+
"containerPath" : "container:",
26+
"identifier" : "NBKFlexibleWidthKitTests",
27+
"name" : "NBKFlexibleWidthKitTests"
28+
}
29+
}
30+
],
31+
"version" : 1
32+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1430"
4+
version = "1.7">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "NBKFlexibleWidthKit"
18+
BuildableName = "NBKFlexibleWidthKit"
19+
BlueprintName = "NBKFlexibleWidthKit"
20+
ReferencedContainer = "container:">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Release"
27+
selectedDebuggerIdentifier = ""
28+
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<TestPlans>
31+
<TestPlanReference
32+
reference = "container:.swiftpm/NBKFlexibleWidthKit.xctestplan">
33+
</TestPlanReference>
34+
<TestPlanReference
35+
reference = "container:.swiftpm/NBKFlexibleWidthKit-Benchmarks.xctestplan"
36+
default = "YES">
37+
</TestPlanReference>
38+
</TestPlans>
39+
</TestAction>
40+
<LaunchAction
41+
buildConfiguration = "Release"
42+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
43+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
44+
launchStyle = "0"
45+
useCustomWorkingDirectory = "NO"
46+
ignoresPersistentStateOnLaunch = "NO"
47+
debugDocumentVersioning = "YES"
48+
debugServiceExtension = "internal"
49+
allowLocationSimulation = "YES">
50+
</LaunchAction>
51+
<ProfileAction
52+
buildConfiguration = "Release"
53+
shouldUseLaunchSchemeArgsEnv = "YES"
54+
savedToolIdentifier = "Time Profiler"
55+
useCustomWorkingDirectory = "NO"
56+
debugDocumentVersioning = "YES">
57+
<MacroExpansion>
58+
<BuildableReference
59+
BuildableIdentifier = "primary"
60+
BlueprintIdentifier = "NBKFlexibleWidthKit"
61+
BuildableName = "NBKFlexibleWidthKit"
62+
BlueprintName = "NBKFlexibleWidthKit"
63+
ReferencedContainer = "container:">
64+
</BuildableReference>
65+
</MacroExpansion>
66+
</ProfileAction>
67+
<AnalyzeAction
68+
buildConfiguration = "Release">
69+
</AnalyzeAction>
70+
<ArchiveAction
71+
buildConfiguration = "Release"
72+
revealArchiveInOrganizer = "YES">
73+
</ArchiveAction>
74+
</Scheme>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1430"
4+
version = "1.7">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "NBKFlexibleWidthKit"
18+
BuildableName = "NBKFlexibleWidthKit"
19+
BlueprintName = "NBKFlexibleWidthKit"
20+
ReferencedContainer = "container:">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<TestPlans>
31+
<TestPlanReference
32+
reference = "container:.swiftpm/NBKFlexibleWidthKit.xctestplan"
33+
default = "YES">
34+
</TestPlanReference>
35+
</TestPlans>
36+
</TestAction>
37+
<LaunchAction
38+
buildConfiguration = "Debug"
39+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
40+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
41+
launchStyle = "0"
42+
useCustomWorkingDirectory = "NO"
43+
ignoresPersistentStateOnLaunch = "NO"
44+
debugDocumentVersioning = "YES"
45+
debugServiceExtension = "internal"
46+
allowLocationSimulation = "YES">
47+
</LaunchAction>
48+
<ProfileAction
49+
buildConfiguration = "Release"
50+
shouldUseLaunchSchemeArgsEnv = "YES"
51+
savedToolIdentifier = ""
52+
useCustomWorkingDirectory = "NO"
53+
debugDocumentVersioning = "YES">
54+
<MacroExpansion>
55+
<BuildableReference
56+
BuildableIdentifier = "primary"
57+
BlueprintIdentifier = "NBKFlexibleWidthKit"
58+
BuildableName = "NBKFlexibleWidthKit"
59+
BlueprintName = "NBKFlexibleWidthKit"
60+
ReferencedContainer = "container:">
61+
</BuildableReference>
62+
</MacroExpansion>
63+
</ProfileAction>
64+
<AnalyzeAction
65+
buildConfiguration = "Debug">
66+
</AnalyzeAction>
67+
<ArchiveAction
68+
buildConfiguration = "Release"
69+
revealArchiveInOrganizer = "YES">
70+
</ArchiveAction>
71+
</Scheme>

Package.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ let package = Package(
4848
.library(
4949
name: "NBKDoubleWidthKit",
5050
targets: ["NBKDoubleWidthKit"]),
51+
//=--------------------------------------=
52+
// NBK x Flexible Width Kit
53+
//=--------------------------------------=
54+
.library(
55+
name: "NBKFlexibleWidthKit",
56+
targets: ["NBKFlexibleWidthKit"]),
5157
],
5258
targets: [
5359
//=--------------------------------------=
@@ -84,6 +90,20 @@ let package = Package(
8490
.testTarget(
8591
name: "NBKDoubleWidthKitTests",
8692
dependencies: ["NBKDoubleWidthKit"]),
93+
//=--------------------------------------=
94+
// NBK x Flexible Width Kit
95+
//=--------------------------------------=
96+
.target(
97+
name: "NBKFlexibleWidthKit",
98+
dependencies: ["NBKCoreKit"]),
99+
100+
.testTarget(
101+
name: "NBKFlexibleWidthKitBenchmarks",
102+
dependencies: ["NBKFlexibleWidthKit"]),
103+
104+
.testTarget(
105+
name: "NBKFlexibleWidthKitTests",
106+
dependencies: ["NBKFlexibleWidthKit"]),
87107
]
88108
)
89109

README.md

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
* [NBKCoreKit](#nbkcorekit)
1212
* [NBKDoubleWidthKit](#nbkdoublewidthkit)
13+
* [NBKFlexibleWidthKit](#nbkflexiblewidthkit)
1314
* [Installation](#installation)
1415
* [Acknowledgements](#acknowledgements)
1516

@@ -113,6 +114,43 @@ Int256(5) % Int(5), UInt256(5) % UInt(5)
113114
> [!NOTE]
114115
> You can use `StaticString` until `StaticBigInt` becomes available.
115116
117+
<a name="nbkflexiblewidthkit"/>
118+
119+
## [NBKFlexibleWidthKit][FLX/D] ([Sources][FLX/S], [Tests][FLX/T], [Benchmarks][FLX/B])
120+
121+
> [!IMPORTANT]
122+
> It's a work in progress. I may rework it at any time.
123+
124+
### Models
125+
126+
- [NBKFibonacciXL](Sources/NBKFlexibleWidthKit/Models/NBKFibonacciXL.swift)
127+
- [UIntXL](Sources/NBKFlexibleWidthKit/Models/NBKFlexibleWidth.swift)
128+
129+
### Fibonacci
130+
131+
```swift
132+
NBKFibonacciXL(0) // (index: 0, element: 0, next: 1)
133+
NBKFibonacciXL(1) // (index: 1, element: 1, next: 1)
134+
NBKFibonacciXL(2) // (index: 2, element: 1, next: 2)
135+
NBKFibonacciXL(3) // (index: 3, element: 2, next: 3)
136+
NBKFibonacciXL(4) // (index: 4, element: 3, next: 5)
137+
NBKFibonacciXL(5) // (index: 5, element: 5, next: 8)
138+
```
139+
140+
It uses a fast double-and-add algorithm:
141+
142+
```swift
143+
NBKFibonacciXL(10_000_000) // 2.3s on M1 MacBook Pro
144+
```
145+
146+
But you can also step through it manually:
147+
148+
```swift
149+
public mutating func increment() { ... } // index + 1
150+
public mutating func decrement() { ... } // index - 1
151+
public mutating func double() { ... } // index * 2
152+
```
153+
116154
<a name="installation"/>
117155

118156
## Installation
@@ -138,9 +176,10 @@ Add this package to your list of package dependencies.
138176
Choose target dependencies from the products in [Package.swift](Package.swift).
139177

140178
```swift
141-
.product(name: "Numberick", package: "Numberick"),
142-
.product(name: "NBKCoreKit", package: "Numberick"),
143-
.product(name: "NBKDoubleWidthKit", package: "Numberick"),
179+
.product(name: "Numberick", package: "Numberick"),
180+
.product(name: "NBKCoreKit", package: "Numberick"),
181+
.product(name: "NBKDoubleWidthKit", package: "Numberick"),
182+
.product(name: "NBKFlexibleWidthKit", package: "Numberick"),
144183
```
145184

146185
### Using [CocoaPods](http://cocoapods.org)
@@ -163,15 +202,20 @@ This project is inspired by [**Int128**][Apple/Int128] and [**DoubleWidth**][App
163202

164203
[NBK/D]: https://oscbyspro.github.io/Numberick/documentation/numberick
165204
[DBL/D]: https://oscbyspro.github.io/Numberick/documentation/numberick/nbkdoublewidth
205+
[FLX/D]: https://oscbyspro.github.io/Numberick/documentation/numberick/nbkflexiblewidth
206+
[SIG/D]: https://oscbyspro.github.io/Numberick/documentation/numberick/nbksigned
166207

167208
[COR/S]: Sources/NBKCoreKit
168209
[DBL/S]: Sources/NBKDoubleWidthKit
210+
[FLX/S]: Sources/NBKFlexibleWidthKit
169211

170212
[COR/T]: Tests/NBKCoreKitTests
171213
[DBL/T]: Tests/NBKDoubleWidthKitTests
214+
[FLX/T]: Tests/NBKFlexibleWidthKitTests
172215

173216
[COR/B]: Tests/NBKCoreKitBenchmarks
174217
[DBL/B]: Tests/NBKDoubleWidthKitBenchmarks
218+
[FLX/B]: Tests/NBKFlexibleWidthKitBenchmarks
175219

176220
<!-- Links x Miscellaneous -->
177221

Sources/NBKCoreKit/Models/NBKPrimeSieve.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ extension NBKPrimeSieve {
717717
/// 5) [6A, 6B, 2A, 6D, 6E, 2B] // 6B, 6E
718718
/// 6) [6A, 6B, 6C, 6D, 6E, 6F] // 6C, 6F
719719
///
720-
/// The idea is to reuse words and subsequences whenever possible.
720+
/// The idea is to reuse elements and subsequences whenever possible.
721721
///
722722
/// - Important: The sieve culls even numbers by omission, so start with `[3,5]`.
723723
///
@@ -736,7 +736,7 @@ extension NBKPrimeSieve {
736736
patternIndex.remainder &+= current.prime
737737
}; chunk.formOnesComplement()
738738
//=--------------------------=
739-
// pattern: reuse words
739+
// pattern: reuse elements
740740
//=--------------------------=
741741
var ((destination)) = patternIndex.quotient
742742
while destination < current.product {

0 commit comments

Comments
 (0)