Claim your blog
Record · corpus.blog/posts/01a08789-803c-7129-942f-6f850f41d369

Object Soup is Made of Indexes

jacko.io · published 23 October 2023

A record is what was published and who pointed at it. The text of the post is not held here: read it at the source, or at its Wayback capture.

0blogs citing
First cited
—
Most recent
—
Rank this month
not ranked
External links
46
Words captured
2,922

Cited by

No blog we hold has cited this post yet.

Links from this post

Link
Host
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&code=use+std%3A%3Acell%3A%3A%7BRefCell%2C+RefMut%7D%3B%0Ause+std%3A%3Aops%3A%3A%7BDeref%2C+DerefMut%7D%3B%0Ause+std%3A%3Arc%3A%3ARc%3B%0A%0Astruct+Person+%7B%0A++++_name%3A+String%2C%0A++++friends%3A+Vec%3CRc%3CRefCell%3CPerson%3E%3E%3E%2C%0A%7D%0A%0Aimpl+Person+%7B%0A++++fn+new%28name%3A+%26str%29+-%3E+Person+%7B%0A++++++++Person+%7B+_name%3A+name.into%28%29%2C+friends%3A+Vec%3A%3Anew%28%29+%7D%0A++++%7D%0A%0A++++fn+add_friend%28%26mut+self%2C+other%3A+Rc%3CRefCell%3CPerson%3E%3E%29+%7B%0A++++++++self.friends.push%28other%29%3B%0A++++%7D%0A%7D%0A%0Afn+main%28%29+%7B%0A++++let+alice+%3D+Rc%3A%3Anew%28RefCell%3A%3Anew%28Person%3A%3Anew%28%22Alice%22%29%29%29%3B%0A++++let+bob+%3D+Rc%3A%3Anew%28RefCell%3A%3Anew%28Person%3A%3Anew%28%22Bob%22%29%29%29%3B%0A%0A++++%2F%2F+alice.borrow_mut%28%29.add_friend%28Rc%3A%3Aclone%28%26bob%29%29%3B%0A++++let+alice_refcell%3A++++%26RefCell%3CPerson%3E++++%3D+alice.deref%28%29%3B%0A++++let+mut+alice_refmut%3A+RefMut%3CPerson%3E++++++%3D+alice_refcell.borrow_mut%28%29%3B%0A++++let+alice_mut%3A++++++++%26mut+Person+++++++++%3D+alice_refmut.deref_mut%28%29%3B%0A++++let+bob_alias%3A++++++++Rc%3CRefCell%3CPerson%3E%3E+%3D+Rc%3A%3Aclone%28%26bob%29%3B%0A++++alice_mut.add_friend%28bob_alias%29%3B%0A++++drop%28alice_refmut%29%3B%0A%0A++++%2F%2F+bob.borrow_mut%28%29.add_friend%28Rc%3A%3Aclone%28%26alice%29%29%3B%0A++++let+bob_refcell%3A++++%26RefCell%3CPerson%3E++++%3D+bob.deref%28%29%3B%0A++++let+mut+bob_refmut%3A+RefMut%3CPerson%3E++++++%3D+bob_refcell.borrow_mut%28%29%3B%0A++++let+bob_mut%3A++++++++%26mut+Person+++++++++%3D+bob_refmut.deref_mut%28%29%3B%0A++++let+alice_alias%3A++++Rc%3CRefCell%3CPerson%3E%3E+%3D+Rc%3A%3Aclone%28%26alice%29%3B%0A++++bob_mut.add_friend%28alice_alias%29%3B%0A++++drop%28bob_refmut%29%3B%0A%7D
play.rust-lang.org
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&code=use+rayon%3A%3Aprelude%3A%3A*%3B%0Ause+std%3A%3Athread%3A%3Asleep%3B%0Ause+std%3A%3Atime%3A%3A%7BDuration%2C+Instant%7D%3B%0A%0Astruct+Person+%7B%0A++++name%3A+String%2C%0A++++friends%3A+Vec%3Cusize%3E%2C%0A%7D%0A%0Afn+new_person%28people%3A+%26mut+Vec%3CPerson%3E%2C+name%3A+%26str%29+-%3E+usize+%7B%0A++++people.push%28Person+%7B+name%3A+name.into%28%29%2C+friends%3A+Vec%3A%3Anew%28%29+%7D%29%3B%0A++++people.len%28%29+-+1%0A%7D%0A%0Afn+add_friend%28people%3A+%26mut+Vec%3CPerson%3E%2C+this_id%3A+usize%2C+other_id%3A+usize%29+%7B%0A++++if+people%5Bother_id%5D.name+%21%3D+people%5Bthis_id%5D.name+%7B%0A++++++++people%5Bthis_id%5D.friends.push%28other_id%29%3B%0A++++%7D%0A%7D%0A%0Afn+main%28%29+%7B%0A++++let+mut+people+%3D+Vec%3A%3Anew%28%29%3B%0A++++let+alice_id+%3D+new_person%28%26mut+people%2C+%22Alice%22%29%3B%0A++++let+bob_id+%3D+new_person%28%26mut+people%2C+%22Bob%22%29%3B%0A++++add_friend%28%26mut+people%2C+alice_id%2C+bob_id%29%3B%0A++++add_friend%28%26mut+people%2C+bob_id%2C+alice_id%29%3B%0A++++add_friend%28%26mut+people%2C+alice_id%2C+alice_id%29%3B+%2F%2F+no-op%0A%0A++++%2F%2F+Iterate+over+the+people+Vec+using+multiple+threads.+We+sleep+1+second+for%0A++++%2F%2F+each+person%2C+so+if+this+were+a+single-threaded+loop+it+would+take+2%0A++++%2F%2F+seconds.+But+because+it%27s+multithreaded%2C+it+only+takes+1+second.%0A++++let+start+%3D+Instant%3A%3Anow%28%29%3B%0A++++people.par_iter%28%29.for_each%28%7Cperson%7C+%7B%0A++++++++sleep%28Duration%3A%3Afrom_secs%281%29%29%3B%0A++++++++println%21%28%22%7B%7D%22%2C+person.name%29%3B%0A++++%7D%29%3B%0A++++println%21%28%22Total+time%3A+%7B%3A%3F%7D%22%2C+Instant%3A%3Anow%28%29.duration_since%28start%29%29%3B%0A%7D
play.rust-lang.org