{"id":13668024,"url":"https://github.com/siriusdemon/rusticode","last_synced_at":"2025-04-13T17:32:49.460Z","repository":{"id":127944601,"uuid":"275731576","full_name":"siriusdemon/rusticode","owner":"siriusdemon","description":"是树和链表，快跑！","archived":false,"fork":false,"pushed_at":"2020-10-27T01:38:35.000Z","size":156,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T08:17:23.998Z","etag":null,"topics":["leetcode","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/siriusdemon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-06-29T04:39:10.000Z","updated_at":"2021-09-11T01:03:49.000Z","dependencies_parsed_at":"2024-01-14T16:17:14.343Z","dependency_job_id":"3b8c1779-bd4a-4fae-b63f-108007aaac4f","html_url":"https://github.com/siriusdemon/rusticode","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/siriusdemon%2Frusticode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/siriusdemon%2Frusticode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/siriusdemon%2Frusticode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/siriusdemon%2Frusticode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/siriusdemon","download_url":"https://codeload.github.com/siriusdemon/rusticode/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248752385,"owners_count":21156081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["leetcode","rust"],"created_at":"2024-08-02T07:01:00.439Z","updated_at":"2025-04-13T17:32:49.440Z","avatar_url":"https://github.com/siriusdemon.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# rusticode\n\n是树和链表，快跑！\n\n\n#### 初心\n\n刚用`rust`写`leetcode`的时候，一遇到树和链表的题，就满地`clone`，才能通过编译。后面对`rust`熟悉了之后，就找到了一些避免多余副本的方法。因为每一个副本都需要消耗内存，克隆的操作可能也会比较耗时。如果一直`clone`，速度和效率就大打折扣了。相比隔壁的`C`，虽然有了自动内存管理，但却是以拷贝作为代价。\n\n概括地说，避免不必要`clone`的方法是：\n\n+ 使用引用，适用于不需要修改原数据结构的场景，比如树的深度，链表的长度。\n+ 使用`take`，适用于需要修改原数据结构的场景，比如重建二叉树。\n\n对于那些正在用`rust`写题的同学，可能树和链表的代码是最有参考性的。\n\n+ [tree.rs](leetcode/src/tree.rs)\n+ [ilist.rs](leetcode/src/ilist.rs)\n\n#### misc\n\n你可以通过`cargo`跑测试。这里面的测试并没有涵盖所有的题目。一开始，每做一题我都会在`lib.rs`写对应的测试，后来觉得太麻烦就没有写了。\n```sh\ncargo test\n```\n\n如果你想在`rust`中写`C`，这个项目也有一点点的参考价值。你可以看看`lib.rs`和`leetcode.c`是怎么交互的。\n\n\n\n#### wishes\n\n愿凡有所得，皆能自利利他。","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsiriusdemon%2Frusticode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsiriusdemon%2Frusticode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsiriusdemon%2Frusticode/lists"}