You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by GitBox <gi...@apache.org> on 2021/07/15 16:01:34 UTC

[GitHub] [incubator-brpc] serverglen opened a new pull request #1484: Add FlatMap example code

serverglen opened a new pull request #1484:
URL: https://github.com/apache/incubator-brpc/pull/1484


   Add FlatMap example code


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] zyearn merged pull request #1484: Add FlatMap example code

Posted by GitBox <gi...@apache.org>.
zyearn merged pull request #1484:
URL: https://github.com/apache/incubator-brpc/pull/1484


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] zyearn commented on a change in pull request #1484: Add FlatMap example code

Posted by GitBox <gi...@apache.org>.
zyearn commented on a change in pull request #1484:
URL: https://github.com/apache/incubator-brpc/pull/1484#discussion_r671641855



##########
File path: docs/cn/flatmap.md
##########
@@ -4,7 +4,35 @@ FlatMap - Maybe the fastest hashmap, with tradeoff of space.
 
 # EXAMPLE
 
-`#include <butil/containers/flat_map.h>`
+```c++
+#include <string>
+#include <butil/logging.h>
+#include <butil/containers/flat_map.h>
+
+void flatmap_example(
+    butil::FlatMap<int, std::string> map;
+    // bucket_count: initial count of buckets, big enough to avoid resize.
+    // load_factor: element_count * 100 / bucket_count, 80 as default.
+    int bucket_count = 1000;
+    int load_factor = 80;
+    map.init(bucket_count, load_factor);
+    map.insert(10, "hello");
+    map[20] = "world";
+    std::string* value = map.seek(20);
+    CHECK_EQ(true, value != NULL);

Review comment:
       nit: 这边直接写成CHECK(value != NULL)会看起来直接一些




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] zyearn merged pull request #1484: Add FlatMap example code

Posted by GitBox <gi...@apache.org>.
zyearn merged pull request #1484:
URL: https://github.com/apache/incubator-brpc/pull/1484


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] zyearn commented on a change in pull request #1484: Add FlatMap example code

Posted by GitBox <gi...@apache.org>.
zyearn commented on a change in pull request #1484:
URL: https://github.com/apache/incubator-brpc/pull/1484#discussion_r671641685



##########
File path: docs/cn/flatmap.md
##########
@@ -4,7 +4,35 @@ FlatMap - Maybe the fastest hashmap, with tradeoff of space.
 
 # EXAMPLE
 
-`#include <butil/containers/flat_map.h>`
+```c++
+#include <string>
+#include <butil/logging.h>
+#include <butil/containers/flat_map.h>
+
+void flatmap_example(

Review comment:
       这边是不是少了 ') {'

##########
File path: docs/cn/flatmap.md
##########
@@ -4,7 +4,35 @@ FlatMap - Maybe the fastest hashmap, with tradeoff of space.
 
 # EXAMPLE
 
-`#include <butil/containers/flat_map.h>`
+```c++
+#include <string>
+#include <butil/logging.h>
+#include <butil/containers/flat_map.h>
+
+void flatmap_example(
+    butil::FlatMap<int, std::string> map;
+    // bucket_count: initial count of buckets, big enough to avoid resize.
+    // load_factor: element_count * 100 / bucket_count, 80 as default.
+    int bucket_count = 1000;
+    int load_factor = 80;
+    map.init(bucket_count, load_factor);
+    map.insert(10, "hello");
+    map[20] = "world";
+    std::string* value = map.seek(20);
+    CHECK_EQ(true, value != NULL);

Review comment:
       这边直接写成CHECK(value != NULL)会看起来直接一些




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] serverglen commented on pull request #1484: Add FlatMap example code

Posted by GitBox <gi...@apache.org>.
serverglen commented on pull request #1484:
URL: https://github.com/apache/incubator-brpc/pull/1484#issuecomment-881221635


   @zyearn  已修改,辛苦再review下,thanks!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] wasphin commented on a change in pull request #1484: Add FlatMap example code

Posted by GitBox <gi...@apache.org>.
wasphin commented on a change in pull request #1484:
URL: https://github.com/apache/incubator-brpc/pull/1484#discussion_r671696210



##########
File path: docs/cn/flatmap.md
##########
@@ -4,7 +4,35 @@ FlatMap - Maybe the fastest hashmap, with tradeoff of space.
 
 # EXAMPLE
 
-`#include <butil/containers/flat_map.h>`
+```c++
+#include <string>
+#include <butil/logging.h>
+#include <butil/containers/flat_map.h>
+
+void flatmap_example() {
+    butil::FlatMap<int, std::string> map;
+    // bucket_count: initial count of buckets, big enough to avoid resize.
+    // load_factor: element_count * 100 / bucket_count, 80 as default.
+    int bucket_count = 1000;
+    int load_factor = 80;
+    map.init(bucket_count, load_factor);
+    map.insert(10, "hello");
+    map[20] = "world";
+    std::string* value = map.seek(20);
+    CHECK(value != NULL)

Review comment:
       少一个 `;`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] zyearn commented on a change in pull request #1484: Add FlatMap example code

Posted by GitBox <gi...@apache.org>.
zyearn commented on a change in pull request #1484:
URL: https://github.com/apache/incubator-brpc/pull/1484#discussion_r670801803



##########
File path: docs/cn/flatmap.md
##########
@@ -4,7 +4,29 @@ FlatMap - Maybe the fastest hashmap, with tradeoff of space.
 
 # EXAMPLE
 
-`#include <butil/containers/flat_map.h>`
+```c++
+#include <string>
+#include <butil/containers/flat_map.h>
+
+butil::FlatMap<int, std::string> map;
+// bucket_count: initial count of buckets, big enough to avoid resize.
+// load_factor: element_count * 100 / bucket_count, 80 as default.
+int bucket_count = 1000;
+int load_factor = 80;
+map.init(bucket_count, load_factor);
+map.insert(10, "hello");
+map[20] = "world";
+std::string* value = map.seek(20);
+if (value != NULL) {
+    LOG(TRACE) << "Got the value=" << *value;
+} else {
+    LOG(FATAL) << "Impossible, we've just put the value in";
+}

Review comment:
       可以再加上erase, size的用法吗,也比较常见

##########
File path: docs/cn/flatmap.md
##########
@@ -4,7 +4,29 @@ FlatMap - Maybe the fastest hashmap, with tradeoff of space.
 
 # EXAMPLE
 
-`#include <butil/containers/flat_map.h>`
+```c++
+#include <string>
+#include <butil/containers/flat_map.h>
+
+butil::FlatMap<int, std::string> map;
+// bucket_count: initial count of buckets, big enough to avoid resize.
+// load_factor: element_count * 100 / bucket_count, 80 as default.
+int bucket_count = 1000;
+int load_factor = 80;
+map.init(bucket_count, load_factor);
+map.insert(10, "hello");
+map[20] = "world";
+std::string* value = map.seek(20);
+if (value != NULL) {
+    LOG(TRACE) << "Got the value=" << *value;

Review comment:
       brpc不用TRACE,改成INFO可以直接运行

##########
File path: docs/cn/flatmap.md
##########
@@ -4,7 +4,29 @@ FlatMap - Maybe the fastest hashmap, with tradeoff of space.
 
 # EXAMPLE
 
-`#include <butil/containers/flat_map.h>`
+```c++
+#include <string>
+#include <butil/containers/flat_map.h>
+
+butil::FlatMap<int, std::string> map;
+// bucket_count: initial count of buckets, big enough to avoid resize.
+// load_factor: element_count * 100 / bucket_count, 80 as default.
+int bucket_count = 1000;
+int load_factor = 80;
+map.init(bucket_count, load_factor);
+map.insert(10, "hello");
+map[20] = "world";
+std::string* value = map.seek(20);
+if (value != NULL) {
+    LOG(TRACE) << "Got the value=" << *value;

Review comment:
       另外这里可以换成BAIDU_CASSERT(value, value_must_be_non_empty); 来告诉用户预期是什么,用if-else会产生两种结果都会返回的感觉

##########
File path: docs/cn/flatmap.md
##########
@@ -4,7 +4,29 @@ FlatMap - Maybe the fastest hashmap, with tradeoff of space.
 
 # EXAMPLE
 
-`#include <butil/containers/flat_map.h>`
+```c++
+#include <string>
+#include <butil/containers/flat_map.h>
+

Review comment:
       这段代码可以包在一个函数flatmap_example()里吗,这样直接复制也可以运行




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] zyearn merged pull request #1484: Add FlatMap example code

Posted by GitBox <gi...@apache.org>.
zyearn merged pull request #1484:
URL: https://github.com/apache/incubator-brpc/pull/1484


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] serverglen commented on a change in pull request #1484: Add FlatMap example code

Posted by GitBox <gi...@apache.org>.
serverglen commented on a change in pull request #1484:
URL: https://github.com/apache/incubator-brpc/pull/1484#discussion_r671690221



##########
File path: docs/cn/flatmap.md
##########
@@ -4,7 +4,35 @@ FlatMap - Maybe the fastest hashmap, with tradeoff of space.
 
 # EXAMPLE
 
-`#include <butil/containers/flat_map.h>`
+```c++
+#include <string>
+#include <butil/logging.h>
+#include <butil/containers/flat_map.h>
+
+void flatmap_example(
+    butil::FlatMap<int, std::string> map;
+    // bucket_count: initial count of buckets, big enough to avoid resize.
+    // load_factor: element_count * 100 / bucket_count, 80 as default.
+    int bucket_count = 1000;
+    int load_factor = 80;
+    map.init(bucket_count, load_factor);
+    map.insert(10, "hello");
+    map[20] = "world";
+    std::string* value = map.seek(20);
+    CHECK_EQ(true, value != NULL);

Review comment:
       ok




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org