Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IntegerView(s) #83

Open
oscbyspro opened this issue Sep 16, 2023 · 6 comments
Open

IntegerView(s) #83

oscbyspro opened this issue Sep 16, 2023 · 6 comments
Labels
addition oh, so shiny! await can't be done yet brrr such code, much wow maybe to do, or not to do?

Comments

@oscbyspro
Copy link
Owner

oscbyspro commented Sep 16, 2023

I need lots of free-function-y stuff to get things done without tying myself to any particular implementation. But free-function-y stuff is messy. The function signatures get way too long or way too terse. It is difficult to track, and tracking preconditions is worse.

So I've been thinking. I might want integer-view-y stuff instead, so things get neatly encapsulated, preconditions get checked on instantiation, and the type system can help out. I imagine these generic over various collections, but I probably need borrowing and consuming for that. I suppose mutable buffer pointers might do.

withStrictUnsignedInteger(...)
withNormalizedUnsignedInteger(...)
SuccinctUnsignedIntegerView(rebasing: view)
NormalizedUnsignedIntegerView(validating: view)
@oscbyspro oscbyspro added addition oh, so shiny! brrr such code, much wow labels Sep 16, 2023
@oscbyspro oscbyspro added this to the v0.13.0 milestone Sep 16, 2023
@oscbyspro oscbyspro added the maybe to do, or not to do? label Sep 16, 2023
@oscbyspro
Copy link
Owner Author

oscbyspro commented Sep 17, 2023

One with...(_:) instead of multiple free-function shims is Greatness™

I have a dream ...of views without closures.

@oscbyspro oscbyspro removed the maybe to do, or not to do? label Sep 17, 2023
@oscbyspro
Copy link
Owner Author

oscbyspro commented Sep 18, 2023

Hm. I've had a hard time getting this to perform well with NBKDoubleWidth (shifts). It appears that NBKStrictBitPattern<UnsafeMutableBufferPointer<UInt>> is slow. I'm not sure why. I got close with NBKStrictBitPattern<UnsafeMutableWords>, however, where UnsafeMutableWords is a custom NBKDoubleWidth pointer.

@oscbyspro
Copy link
Owner Author

oscbyspro commented Sep 20, 2023

I'm basically hoping I can turn these into views when Swift gets those, that would be great. Maybe I should still go the custom-NBKDoubleWidth-pointer route until then, because the need for static methods is so silly. Hm. I'll think about it.

@oscbyspro
Copy link
Owner Author

oscbyspro commented Sep 20, 2023

So I realized something. Given how binary integers are tree-like, I could wrap sub-views in super-views. Maybe the compiler likes that better than converting back and forth between views? Conversions seem like they might require lots of ownership fiddling that isn't possible in Swift 5.7 or 5.8. Maybe I can do something cool with @dynamicMemberLookup too.

Edit: Doesn't seem like wrapping performs any better or worse (maybe non-pointers care).

Edit: Nope. Nope. Nope. @dynamicMemberLookup turns out to be dynamic. Who'd a thunk it?

oscbyspro added a commit that referenced this issue Sep 20, 2023
@oscbyspro
Copy link
Owner Author

oscbyspro commented Sep 21, 2023

Free functions are hard to beat. Should I use static methods and retry when Swift gets proper views? Hm.

oscbyspro added a commit that referenced this issue Sep 21, 2023
@oscbyspro
Copy link
Owner Author

oscbyspro commented Sep 21, 2023

I kept the namespaces but removed the views. I feel like the namespaces help keep things nice and tidy.

@oscbyspro oscbyspro closed this as not planned Won't fix, can't repro, duplicate, stale Sep 21, 2023
@oscbyspro oscbyspro reopened this Sep 21, 2023
@oscbyspro oscbyspro added await can't be done yet maybe to do, or not to do? labels Sep 21, 2023
@oscbyspro oscbyspro removed this from the v0.13.0 milestone Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition oh, so shiny! await can't be done yet brrr such code, much wow maybe to do, or not to do?
Projects
None yet
Development

No branches or pull requests

1 participant