ur5us_ has quit [Remote host closed the connection]
ur5us_ has joined #crystal-lang
ur5us_ has quit [Ping timeout: 245 seconds]
<FromGitter>
<aaaScript> Would anyone know if there's an example or implementation of the following from Ruby? ⏎ ⏎ ```IPAddr.new("127.0.0.1/8").include? "127.1.10.200"``` ⏎ ⏎ I'm basically trying to see if an IP is within the range of a CIDR. Taking a look at the API it looks like Socket::IPAddress may not support it. Wondering if anyone has worked on anything like this before I tackle a custom solution.
<yxhuvud>
@straight-shoota: While ruby doesn't have overloading, it DO have separate unary and binary +.
<yxhuvud>
unary is referred to as @+.
<yxhuvud>
in method definitions etc.
<yxhuvud>
eh, +@.
notzmv has joined #crystal-lang
<FromGitter>
<Dan-Do> How to push items to Slice?
<FromGitter>
<naqvis> you can’t push, but use index [] operator
<FromGitter>
<naqvis> if you need pushing items then Slice doesn’t look like right choice for your use case
<FromGitter>
<Dan-Do> How about Pointer?
<FromGitter>
<Dan-Do> With Slice, I can use .to_a then push then convert back to Slice. But I don't think it's efficient
<FromGitter>
<naqvis> Slice is Pointer in disguise
<FromGitter>
<naqvis> what’s your use case?
<FromGitter>
<christopherzimmerman> Why not just use an array? If you need to access the pointer you can do that as well, but it gives you all the utility of resizing and appending.
<FromGitter>
<Dan-Do> I have a fun in C binding return Pointer(Void). Actually it's an array of UInt64. Now I want to push more items to it
<FromGitter>
<Dan-Do> @naqvis I see this `private def compress(src : Slice, dst : Slice)` on your snappy lib.
<FromGitter>
<Dan-Do> I don't know what is the type of Slice? Is it Slice(UInt8) or ...?
<FromGitter>
<naqvis> i used that as a type annotation, but use-case in that particular shard is `Slice(UInt8)`
<FromGitter>
<naqvis> > I have a fun in C binding return Pointer(Void). Actually it's an array of UInt64. Now I want to push more items to it ⏎ ⏎ you can do something like ⏎ ⏎ ```my_c_fun(arr.to_unsafe)``` [https://gitter.im/crystal-lang/crystal?at=619f8a56197fa95a1c8e202a]
<FromGitter>
<Dan-Do> Is it fast? because it's told that `Use structs when possible`
<FromGitter>
<Dan-Do> BTW, do you have any experience in C++ binding? I want to make binding for simdjson
<FromGitter>
<Dan-Do> Is it the same as C binding?
taskylizard__ has joined #crystal-lang
<straight-shoota>
Dan-Do does that code even work? At one point you treat `s_from_c` as a struct with a `size` field, and then it's a pointer to a UInt64 array
<straight-shoota>
I can't see how that would be valid
<FromGitter>
<Dan-Do> Oops, just a pseudo code, the `size` is gotten from C lib as `out`
<straight-shoota>
ah, okay
<straight-shoota>
Still, that's most likely unsafe. I assume the pointer comes from the lib, so the memory is allocated there as well.
<FromGitter>
<Dan-Do> Yeap, it's a struct with data and size :)
<straight-shoota>
You can't just add more data to that, unless you're sure there is enough capacity for that
<FromGitter>
<Dan-Do> Does Crystal assure that when running this code `Slice(UInt64).new`?
<straight-shoota>
Like if the array is allocated for 10 elements, but only 4 are populated. The size is 4 and you can still add 6 more items.
<straight-shoota>
No. In that constructor you tell slice that you have a pointer that points to size + 1 elements. It's your responsibility to make sure there is actually capacity for size + 1
<FromGitter>
<Dan-Do> Let me check the crystal's Slice code :)
<FromGitter>
<Dan-Do> You're correct, that code doesn't allocate memory, just wrap the Pointer
taskylizard__ has quit [Ping timeout: 260 seconds]
taskylizard has quit [Ping timeout: 260 seconds]
hightower2 has joined #crystal-lang
<hightower2>
Ah remind me please, what's the best way to check if x == y is actually the same object/instance (and not just being equal according to `==`)
<FromGitter>
<Blacksmoke16> `x.same? y`
<FromGitter>
<Blacksmoke16> only works for reference types ofc tho
<hightower2>
mm, nice, thanks
<frojnd>
Hi there. I would like to match only part that is before `-` together with `-` so the only not matched part of a string would be: `string I would like not to match` But I don't know how to do it. I'm missing part how to also select `-` together with a following space: https://regex101.com/r/bJ1mU0/1