Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
080faed
完成了readme简介撰写
jayuCH Apr 21, 2025
2ff839e
修复了ticket_map.hpp的报错
jayuCH Apr 21, 2025
6efd155
ticketmap运行测试代码
jayuCH Apr 21, 2025
6126956
Merge pull request #1 from jayuCH/main
zhy888ai Apr 21, 2025
a2bd730
Update test.cpp
jayuCH Apr 21, 2025
aa15bf2
Merge pull request #2 from jayuCH/main
zhy888ai Apr 21, 2025
426b90c
更新了一个方法
jayuCH Apr 23, 2025
481b4b4
Readme中的一些图文介绍
jayuCH Apr 23, 2025
6f7a38e
Update Readme(Chinese_Version).md
jayuCH Apr 23, 2025
241ad06
Update Readme(Chinese_Version).md
jayuCH Apr 23, 2025
4f4d802
Update Readme(Chinese_Version).md
jayuCH Apr 23, 2025
9d1b4da
#3 陈佳宇的第三次合并
zhy888ai Apr 23, 2025
eab65fd
完成了第一次撰写
ccyuc23 May 4, 2025
cac7ebc
Merge pull request #4 from ccyuc23/main
zhy888ai May 7, 2025
14022fd
1
idyiyi May 7, 2025
b41b375
第一次提交
ggggg2024 May 8, 2025
8ea02cd
Merge pull request #5 from idyiyi/main
zhy888ai May 8, 2025
771111b
Merge pull request #6 from ggggg2024/main
zhy888ai May 8, 2025
c916f3e
2
ggggg2024 May 8, 2025
0d602fd
2
idyiyi May 8, 2025
41b7d22
Merge pull request #7 from idyiyi/main
zhy888ai May 9, 2025
7cc10b6
Update Readme(Chinese_Version).md
theKingofKurumi May 9, 2025
f35021f
Merge pull request #8 from theKingofKurumi/main
zhy888ai May 9, 2025
08b2197
Create modification_log.md
zhy888ai May 10, 2025
4428e7d
Update Readme(Chinese_Version).md
CCer5 May 10, 2025
328f9e2
Add files via upload
CCer5 May 10, 2025
3174416
Merge pull request #10 from CCer5/main
zhy888ai May 10, 2025
622381d
Readme中文版
zhy888ai May 10, 2025
28348be
Readme中文版
zhy888ai May 10, 2025
e391084
Readme中文版
zhy888ai May 10, 2025
709e983
MinGW报错及解决措施
zhy888ai May 10, 2025
6b20a8c
龚祀玲完成了第一次撰写
ggggg2024 May 10, 2025
6417978
龚祀玲完成了第二次撰写
ggggg2024 May 10, 2025
ba6449b
Readme翻译
ccyuc23 May 10, 2025
23ce1a0
Readme翻译和AI工具使用截图
ccyuc23 May 10, 2025
beba2ee
Merge pull request #13 from ccyuc23/main
zhy888ai May 12, 2025
ea5e439
Merge pull request #12 from ggggg2024/main
zhy888ai May 12, 2025
3b3ce04
岑允欣第二次提交
ccyuc23 May 12, 2025
375cad7
3
idyiyi May 12, 2025
006e5df
Merge pull request #15 from idyiyi/main
zhy888ai May 12, 2025
b28af10
Merge pull request #14 from ccyuc23/main
zhy888ai May 12, 2025
efdad38
AI使用截图第三次提交
zhy888ai May 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
445 changes: 445 additions & 0 deletions Readme(Chinese_Version).md

Large diffs are not rendered by default.

Binary file added imges/2205308010325-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imges/2205308010325-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imges/2205308010325-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imges/2205308010345-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imges/2205308010345-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imges/2205308010345-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imges/2205308010358_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imges/2205308010358__1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imges/2205308010358__2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imges/2208305020346-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imges/2208305020346-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imges/2208305020346-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imges/2208305020346_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imges/2208305020346_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imges/2208305020346_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imges/limits头文件补充.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imges/run_problem1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imges/run_solution.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imges/solution.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions modification_log.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

24 changes: 24 additions & 0 deletions test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Created by JYC on 2025/4/22.
//
#include "/ticket_map.hpp"
#include <iostream>

int main() {
jss::ticket_map<int, std::string> map; // 明确使用 jss:: 前缀

// 插入元素并获取分配的票号
auto ticket = map.insert("Hello, World!");
std::cout << "Inserted with ticket: " << ticket << std::endl;

// 通过票号访问元素
std::cout << "Value: " << map[ticket] << std::endl;

// 遍历容器中的所有元素
for (const auto& entry : map) {
std::cout << "Ticket: " << entry.ticket << ", Value: " << entry.value << std::endl;
}

return 0;
}
// 陈佳宇
38 changes: 34 additions & 4 deletions ticket_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#pragma once

#include <limits>
#include <cstdlib>
#include <vector>
#include <algorithm>
Expand Down Expand Up @@ -77,7 +78,7 @@ namespace jss {
value_type value;
};

public:
public:
/// Required iterator typedefs
using reference= value_type;
/// Required iterator typedefs
Expand Down Expand Up @@ -158,37 +159,44 @@ namespace jss {
};

public:
/// Standard iterator typedef
/// Standard iterator typedef、

using iterator= iterator_impl<false>;
/// Standard const_iterator typedef

using const_iterator= iterator_impl<true>;

/// Construct an empty map

constexpr ticket_map() noexcept : nextId(), filledItems(0) {}

/// Construct a map from a range of elements

template <typename Iter>
constexpr ticket_map(Iter first, Iter last) : ticket_map() {
insert(first, last);
}

/// Move-construct from other. The elements of other are transferred to
/// *this; other is left empty

constexpr ticket_map(ticket_map &&other) noexcept :
nextId(std::move(other.nextId)), data(std::move(other.data)),
filledItems(std::move(other.filledItems)) {
other.filledItems= 0;
}
/// Copy-construct from other. *this will have the same elements and
/// next ticket value as other.

constexpr ticket_map(ticket_map const &other)= default;
/// Copy-assign from other

constexpr ticket_map &operator=(ticket_map const &other) {
ticket_map temp(other);
swap(temp);
return *this;
}
/// Move-assign from other

constexpr ticket_map &operator=(ticket_map &&other) noexcept {
ticket_map temp(std::move(other));
swap(temp);
Expand All @@ -197,11 +205,13 @@ namespace jss {

/// Returns true if there are no elements currently in the map, false
/// otherwise

constexpr bool empty() const noexcept {
return size() == 0;
}

/// Returns the number of elements currently in the map

constexpr std::size_t size() const noexcept {
return filledItems;
}
Expand All @@ -210,6 +220,7 @@ namespace jss {
/// Returns the ticket for the new entry.
/// Invalidates any existing iterators into the map.
/// Throws overflow_error if the Ticket values have overflowed.

constexpr Ticket insert(Value v) {
return emplace(std::move(v));
}
Expand All @@ -219,6 +230,7 @@ namespace jss {
/// entry, or end() if no values were inserted.
/// Invalidates any existing iterators into the map.
/// Throws overflow_error if the Ticket values have overflowed.

template <typename Iter>
constexpr iterator insert(Iter first, Iter last) {
auto const index= data.size();
Expand All @@ -232,6 +244,7 @@ namespace jss {
/// is assigned a new ticket value. Returns the ticket for the new
/// entry. Invalidates any existing iterators into the map.
/// Throws overflow_error if the Ticket values have overflowed.

template <typename... Args> constexpr Ticket emplace(Args &&... args) {
if(overflow)
throw std::overflow_error(
Expand All @@ -249,57 +262,70 @@ namespace jss {

/// Find a value in the map by its ticket. Returns an iterator referring
/// to the found element, or end() if no element could be found
/// 通过票证在映射中查找值。返回指向找到元素的迭代器,如果未找到元素则返回 end()
constexpr const_iterator find(const Ticket &ticket) const noexcept {
return {lookup(data, ticket), this};
}

/// Find a value in the map by its ticket. Returns an iterator referring
/// to the found element, or end() if no element could be found
/// 通过票证在映射中查找值。返回指向找到元素的迭代器,如果未找到元素则返回 end()
constexpr iterator find(const Ticket &ticket) noexcept {
return {lookup(data, ticket), this};
}

/// Find a value in the map by its ticket. Returns a reference to the
/// found element. Throws std:out_of_range if the value was not present.
/// 通过票证在映射中查找值。返回指向找到元素的引用。
///如果值不存在,则抛出 std::out_of_range 异常。
constexpr Value &operator[](const Ticket &ticket) {
return index(data, ticket);
}

/// Find a value in the map by its ticket. Returns a reference to the
/// found element. Throws std:out_of_range if the value was not present.
/// 通过票证在映射中查找值。返回指向找到元素的引用。如果值不存在,则抛出 std::out_of_range 异常。
constexpr const Value &operator[](const Ticket &ticket) const {
return index(data, ticket);
}

/// Returns an iterator to the first element, or end() if the container
/// is empty
/// 返回指向第一个元素的迭代器,如果容器为空则返回 end()
constexpr iterator begin() noexcept {
return {next_valid(data.begin()), this};
}

/// Returns an iterator one-past-the-end of the container
/// 返回指向容器末尾后一个元素的 const_iterator
constexpr iterator end() noexcept {
return {data.end(), this};
}

/// Returns a const_iterator to the first element, or end() if the
/// container is empty
/// 返回指向第一个元素的 const_iterator
///如果容器为空则返回 cend()
constexpr const_iterator begin() const noexcept {
return {next_valid(data.begin()), this};
}

/// Returns a const_iterator one-past-the-end of the container
/// 返回指向容器末尾后一个元素的 const_iterator
constexpr const_iterator end() const noexcept {
return {data.end(), this};
}

/// Returns a const_iterator to the first element, or cend() if the
/// container is empty
/// 返回指向第一个元素的 const_iterator
///如果容器为空则返回 cend()
constexpr const_iterator cbegin() const noexcept {
return {next_valid(data.begin()), this};
}

/// Returns a const_iterator one-past-the-end of the container
/// 返回指向容器末尾后一个元素的 const_iterator
constexpr const_iterator cend() const noexcept {
return {data.end(), this};
}
Expand All @@ -309,6 +335,10 @@ namespace jss {
/// if there was no element with the specified ticket.
/// Invalidates any existing iterators into the map.
/// Compacts the data if there are too many empty slots.
/// 删除具有指定票证的元素。如果存在下一个元素,则返回指向下一个元素的迭代器,否则返回 end()。
///如果未找到具有指定票证的元素,则返回 end()。
///删除元素会使得所有现有的映射迭代器失效。
///如果存在过多的空闲槽位,则压缩数据。
constexpr iterator erase(const Ticket &ticket) noexcept {
return {erase_entry(lookup(data, ticket)), this};
}
Expand Down Expand Up @@ -476,4 +506,4 @@ namespace std {
jss::ticket_map<Ticket, Value> &rhs) noexcept {
lhs.swap(rhs);
}
} // namespace std
} // namespace std