hat
hat
MModular
Created by swig. on 4/11/2024 in #questions
Segmentation Error Occurring With Set Implementation
What an interesting bug! Thank you, Maxim, for looking into it
19 replies
MModular
Created by swig. on 4/11/2024 in #questions
Segmentation Error Occurring With Set Implementation
Oh yeah, that looks like the same bug. Crashes for me on Intel i7
def main():
var keys = String('Проснувшись однажды утром после беспокойного сна, Грегор Замза').split(" ")
var d = Dict[String, Int]()
for i in range(len(keys)):
d[keys[i]] = i
def main():
var keys = String('Проснувшись однажды утром после беспокойного сна, Грегор Замза').split(" ")
var d = Dict[String, Int]()
for i in range(len(keys)):
d[keys[i]] = i
19 replies
MModular
Created by swig. on 4/11/2024 in #questions
Segmentation Error Occurring With Set Implementation
I've had seg faults with Dict too (I think Set[T] is just a wrapper around Dict[T, Bool] but correct me if I'm wrong). I'm struggling to produce a minimal example, which is why I haven't posted, but if you check the code I wrote here https://github.com/jmkopper/Advent-of-Code-2022/blob/main/day12/day12.mojo#L11 (reproduced below), I ran into segfaults without taking the quotient modulo a small number
@value
struct Point(KeyElement):
var r: Int
var c: Int

fn __hash__(self) -> Int:
return (hash(self.r) ^ hash(self.c)) % 10_000
@value
struct Point(KeyElement):
var r: Int
var c: Int

fn __hash__(self) -> Int:
return (hash(self.r) ^ hash(self.c)) % 10_000
It doesn't happen for all inputs, just the advent of code input I was working with. It could, of course, be a problem elsewhere, but I haven't seen evidence of that
19 replies
MModular
Created by taalhaataahir01022001 on 3/26/2024 in #questions
String to float
I don't think there is one yet (I may be mistaken). You can of course write your own, but it's surprisingly hard. If you don't care about perfectly adhering to float spec, though, you can do it pretty easily just by converting digits to ints, dividing by the appropriate power of 10, and summing
4 replies