This is an automated email from the ASF dual-hosted git repository.

jinyewu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-graphar.git


The following commit(s) were added to refs/heads/main by this push:
     new 986629ab refactor(cpp): replace int and `-1` sentinels in graph info 
APIs (#878)
986629ab is described below

commit 986629ab1a3af50e30d42371d73daa1b80bff80a
Author: devadhe sb <[email protected]>
AuthorDate: Fri Feb 27 13:47:13 2026 +0530

    refactor(cpp): replace int and `-1` sentinels in graph info APIs (#878)
    
    * refactor(cpp): replace int with size_t and std::optional in GraphInfo APIs
    
    * formatted code
    
    * fix(rust): update FFI bindings to use usize for size_t
    
    * fix(rust): update public info APIs to use usize
    
    * test(rust): update index out-of-bounds tests to use usize::MAX
    
    * removed redundant static_cast and removed unwanted comments
    
    * redundant static_cast and removed unwanted comments #2
---
 cpp/src/graphar/graph_info.cc | 167 +++++++++++++++++++-----------------------
 cpp/src/graphar/graph_info.h  |  25 ++++---
 rust/src/ffi.rs               |  10 +--
 rust/src/info/edge_info.rs    |   8 +-
 rust/src/info/vertex_info.rs  |   8 +-
 5 files changed, 99 insertions(+), 119 deletions(-)

diff --git a/cpp/src/graphar/graph_info.cc b/cpp/src/graphar/graph_info.cc
index fdbac1b3..3ec666e4 100644
--- a/cpp/src/graphar/graph_info.cc
+++ b/cpp/src/graphar/graph_info.cc
@@ -17,6 +17,7 @@
  * under the License.
  */
 
+#include <optional>
 #include <unordered_set>
 #include <utility>
 
@@ -50,12 +51,12 @@ std::string ConcatEdgeTriple(const std::string& src_type,
          dst_type;
 }
 
-template <int NotFoundValue = -1>
-int LookupKeyIndex(const std::unordered_map<std::string, int>& key_to_index,
-                   const std::string& type) {
+std::optional<size_t> LookupKeyIndex(
+    const std::unordered_map<std::string, size_t>& key_to_index,
+    const std::string& type) {
   auto it = key_to_index.find(type);
   if (it == key_to_index.end()) {
-    return NotFoundValue;
+    return std::nullopt;
   }
   return it->second;
 }
@@ -269,7 +270,7 @@ class VertexInfo::Impl {
   std::vector<std::string> labels_;
   std::string prefix_;
   std::shared_ptr<const InfoVersion> version_;
-  std::unordered_map<std::string, int> property_name_to_index_;
+  std::unordered_map<std::string, size_t> property_name_to_index_;
   std::unordered_map<std::string, bool> property_name_to_primary_;
   std::unordered_map<std::string, bool> property_name_to_nullable_;
   std::unordered_map<std::string, std::shared_ptr<DataType>>
@@ -322,19 +323,19 @@ Result<std::string> VertexInfo::GetVerticesNumFilePath() 
const {
   return BuildPath({impl_->prefix_}) + "vertex_count";
 }
 
-int VertexInfo::PropertyGroupNum() const {
-  return static_cast<int>(impl_->property_groups_.size());
+size_t VertexInfo::PropertyGroupNum() const {
+  return impl_->property_groups_.size();
 }
 
 std::shared_ptr<PropertyGroup> VertexInfo::GetPropertyGroup(
     const std::string& property_name) const {
-  int i = LookupKeyIndex(impl_->property_name_to_index_, property_name);
-  return i == -1 ? nullptr : impl_->property_groups_[i];
+  auto i = LookupKeyIndex(impl_->property_name_to_index_, property_name);
+  return i.has_value() ? impl_->property_groups_[i.value()] : nullptr;
 }
 
 std::shared_ptr<PropertyGroup> VertexInfo::GetPropertyGroupByIndex(
-    int index) const {
-  if (index < 0 || index >= static_cast<int>(impl_->property_groups_.size())) {
+    size_t index) const {
+  if (index >= impl_->property_groups_.size()) {
     return nullptr;
   }
   return impl_->property_groups_[index];
@@ -418,20 +419,15 @@ Result<std::shared_ptr<VertexInfo>> 
VertexInfo::RemovePropertyGroup(
   if (property_group == nullptr) {
     return Status::Invalid("property group is nullptr");
   }
-  int idx = -1;
   for (size_t i = 0; i < impl_->property_groups_.size(); i++) {
     if (*(impl_->property_groups_[i]) == *property_group) {
-      idx = i;
-      break;
+      return std::make_shared<VertexInfo>(
+          impl_->type_, impl_->chunk_size_,
+          RemoveVectorElement(impl_->property_groups_, i), impl_->labels_,
+          impl_->prefix_, impl_->version_);
     }
   }
-  if (idx == -1) {
-    return Status::Invalid("property group not found");
-  }
-  return std::make_shared<VertexInfo>(
-      impl_->type_, impl_->chunk_size_,
-      RemoveVectorElement(impl_->property_groups_, static_cast<size_t>(idx)),
-      impl_->labels_, impl_->prefix_, impl_->version_);
+  return Status::Invalid("property group not found");
 }
 
 bool VertexInfo::IsValidated() const { return impl_->is_validated(); }
@@ -667,8 +663,8 @@ class EdgeInfo::Impl {
   std::string prefix_;
   AdjacentListVector adjacent_lists_;
   PropertyGroupVector property_groups_;
-  std::unordered_map<AdjListType, int> adjacent_list_type_to_index_;
-  std::unordered_map<std::string, int> property_name_to_index_;
+  std::unordered_map<AdjListType, size_t> adjacent_list_type_to_index_;
+  std::unordered_map<std::string, size_t> property_name_to_index_;
   std::unordered_map<std::string, bool> property_name_to_primary_;
   std::unordered_map<std::string, bool> property_name_to_nullable_;
   std::unordered_map<std::string, std::shared_ptr<DataType>>
@@ -741,8 +737,8 @@ std::shared_ptr<AdjacentList> EdgeInfo::GetAdjacentList(
   return impl_->adjacent_lists_[it->second];
 }
 
-int EdgeInfo::PropertyGroupNum() const {
-  return static_cast<int>(impl_->property_groups_.size());
+size_t EdgeInfo::PropertyGroupNum() const {
+  return impl_->property_groups_.size();
 }
 
 const PropertyGroupVector& EdgeInfo::GetPropertyGroups() const {
@@ -751,13 +747,13 @@ const PropertyGroupVector& EdgeInfo::GetPropertyGroups() 
const {
 
 std::shared_ptr<PropertyGroup> EdgeInfo::GetPropertyGroup(
     const std::string& property_name) const {
-  int i = LookupKeyIndex(impl_->property_name_to_index_, property_name);
-  return i == -1 ? nullptr : impl_->property_groups_[i];
+  auto i = LookupKeyIndex(impl_->property_name_to_index_, property_name);
+  return i.has_value() ? impl_->property_groups_[i.value()] : nullptr;
 }
 
 std::shared_ptr<PropertyGroup> EdgeInfo::GetPropertyGroupByIndex(
-    int index) const {
-  if (index < 0 || index >= static_cast<int>(impl_->property_groups_.size())) {
+    size_t index) const {
+  if (index >= impl_->property_groups_.size()) {
     return nullptr;
   }
   return impl_->property_groups_[index];
@@ -766,7 +762,7 @@ std::shared_ptr<PropertyGroup> 
EdgeInfo::GetPropertyGroupByIndex(
 Result<std::string> EdgeInfo::GetVerticesNumFilePath(
     AdjListType adj_list_type) const {
   CHECK_HAS_ADJ_LIST_TYPE(adj_list_type);
-  int i = impl_->adjacent_list_type_to_index_.at(adj_list_type);
+  size_t i = impl_->adjacent_list_type_to_index_.at(adj_list_type);
   return BuildPath({impl_->prefix_, impl_->adjacent_lists_[i]->GetPrefix()}) +
          "vertex_count";
 }
@@ -774,7 +770,7 @@ Result<std::string> EdgeInfo::GetVerticesNumFilePath(
 Result<std::string> EdgeInfo::GetEdgesNumFilePath(
     IdType vertex_chunk_index, AdjListType adj_list_type) const {
   CHECK_HAS_ADJ_LIST_TYPE(adj_list_type);
-  int i = impl_->adjacent_list_type_to_index_.at(adj_list_type);
+  size_t i = impl_->adjacent_list_type_to_index_.at(adj_list_type);
   return BuildPath({impl_->prefix_, impl_->adjacent_lists_[i]->GetPrefix()}) +
          "edge_count" + std::to_string(vertex_chunk_index);
 }
@@ -783,7 +779,7 @@ Result<std::string> EdgeInfo::GetAdjListFilePath(
     IdType vertex_chunk_index, IdType edge_chunk_index,
     AdjListType adj_list_type) const {
   CHECK_HAS_ADJ_LIST_TYPE(adj_list_type);
-  int i = impl_->adjacent_list_type_to_index_.at(adj_list_type);
+  size_t i = impl_->adjacent_list_type_to_index_.at(adj_list_type);
   return BuildPath({impl_->prefix_, impl_->adjacent_lists_[i]->GetPrefix()}) +
          "adj_list/part" + std::to_string(vertex_chunk_index) + "/chunk" +
          std::to_string(edge_chunk_index);
@@ -792,7 +788,7 @@ Result<std::string> EdgeInfo::GetAdjListFilePath(
 Result<std::string> EdgeInfo::GetAdjListPathPrefix(
     AdjListType adj_list_type) const {
   CHECK_HAS_ADJ_LIST_TYPE(adj_list_type);
-  int i = impl_->adjacent_list_type_to_index_.at(adj_list_type);
+  size_t i = impl_->adjacent_list_type_to_index_.at(adj_list_type);
   return BuildPath({impl_->prefix_, impl_->adjacent_lists_[i]->GetPrefix()}) +
          "adj_list/";
 }
@@ -800,7 +796,7 @@ Result<std::string> EdgeInfo::GetAdjListPathPrefix(
 Result<std::string> EdgeInfo::GetAdjListOffsetFilePath(
     IdType vertex_chunk_index, AdjListType adj_list_type) const {
   CHECK_HAS_ADJ_LIST_TYPE(adj_list_type);
-  int i = impl_->adjacent_list_type_to_index_.at(adj_list_type);
+  size_t i = impl_->adjacent_list_type_to_index_.at(adj_list_type);
   return BuildPath({impl_->prefix_, impl_->adjacent_lists_[i]->GetPrefix()}) +
          "offset/chunk" + std::to_string(vertex_chunk_index);
 }
@@ -808,7 +804,7 @@ Result<std::string> EdgeInfo::GetAdjListOffsetFilePath(
 Result<std::string> EdgeInfo::GetOffsetPathPrefix(
     AdjListType adj_list_type) const {
   CHECK_HAS_ADJ_LIST_TYPE(adj_list_type);
-  int i = impl_->adjacent_list_type_to_index_.at(adj_list_type);
+  size_t i = impl_->adjacent_list_type_to_index_.at(adj_list_type);
   return BuildPath({impl_->prefix_, impl_->adjacent_lists_[i]->GetPrefix()}) +
          "offset/";
 }
@@ -821,7 +817,7 @@ Result<std::string> EdgeInfo::GetPropertyFilePath(
     return Status::Invalid("property group is nullptr");
   }
   CHECK_HAS_ADJ_LIST_TYPE(adj_list_type);
-  int i = impl_->adjacent_list_type_to_index_.at(adj_list_type);
+  size_t i = impl_->adjacent_list_type_to_index_.at(adj_list_type);
   return BuildPath({impl_->prefix_, impl_->adjacent_lists_[i]->GetPrefix(),
                     property_group->GetPrefix()}) +
          "part" + std::to_string(vertex_chunk_index) + "/chunk" +
@@ -835,7 +831,7 @@ Result<std::string> EdgeInfo::GetPropertyGroupPathPrefix(
     return Status::Invalid("property group is nullptr");
   }
   CHECK_HAS_ADJ_LIST_TYPE(adj_list_type);
-  int i = impl_->adjacent_list_type_to_index_.at(adj_list_type);
+  size_t i = impl_->adjacent_list_type_to_index_.at(adj_list_type);
   return BuildPath({impl_->prefix_, impl_->adjacent_lists_[i]->GetPrefix(),
                     property_group->GetPrefix()});
 }
@@ -886,21 +882,16 @@ Result<std::shared_ptr<EdgeInfo>> 
EdgeInfo::RemoveAdjacentList(
   if (adj_list == nullptr) {
     return Status::Invalid("adj list is nullptr");
   }
-  int idx = -1;
   for (size_t i = 0; i < impl_->adjacent_lists_.size(); i++) {
     if (impl_->adjacent_lists_[i]->GetType() == adj_list->GetType()) {
-      idx = i;
-      break;
+      return std::make_shared<EdgeInfo>(
+          impl_->src_type_, impl_->edge_type_, impl_->dst_type_,
+          impl_->chunk_size_, impl_->src_chunk_size_, impl_->dst_chunk_size_,
+          impl_->directed_, RemoveVectorElement(impl_->adjacent_lists_, i),
+          impl_->property_groups_, impl_->prefix_, impl_->version_);
     }
   }
-  if (idx == -1) {
-    return Status::Invalid("adj list not found");
-  }
-  return std::make_shared<EdgeInfo>(
-      impl_->src_type_, impl_->edge_type_, impl_->dst_type_, 
impl_->chunk_size_,
-      impl_->src_chunk_size_, impl_->dst_chunk_size_, impl_->directed_,
-      RemoveVectorElement(impl_->adjacent_lists_, static_cast<size_t>(idx)),
-      impl_->property_groups_, impl_->prefix_, impl_->version_);
+  return Status::Invalid("adj list not found");
 }
 
 Result<std::shared_ptr<EdgeInfo>> EdgeInfo::AddPropertyGroup(
@@ -927,21 +918,17 @@ Result<std::shared_ptr<EdgeInfo>> 
EdgeInfo::RemovePropertyGroup(
   if (property_group == nullptr) {
     return Status::Invalid("property group is nullptr");
   }
-  int idx = -1;
   for (size_t i = 0; i < impl_->property_groups_.size(); i++) {
     if (*(impl_->property_groups_[i]) == *property_group) {
-      idx = i;
+      return std::make_shared<EdgeInfo>(
+          impl_->src_type_, impl_->edge_type_, impl_->dst_type_,
+          impl_->chunk_size_, impl_->src_chunk_size_, impl_->dst_chunk_size_,
+          impl_->directed_, impl_->adjacent_lists_,
+          RemoveVectorElement(impl_->property_groups_, i), impl_->prefix_,
+          impl_->version_);
     }
   }
-  if (idx == -1) {
-    return Status::Invalid("property group not found");
-  }
-  return std::make_shared<EdgeInfo>(
-      impl_->src_type_, impl_->edge_type_, impl_->dst_type_, 
impl_->chunk_size_,
-      impl_->src_chunk_size_, impl_->dst_chunk_size_, impl_->directed_,
-      impl_->adjacent_lists_,
-      RemoveVectorElement(impl_->property_groups_, static_cast<size_t>(idx)),
-      impl_->prefix_, impl_->version_);
+  return Status::Invalid("property group not found");
 }
 
 bool EdgeInfo::IsValidated() const { return impl_->is_validated(); }
@@ -1115,7 +1102,7 @@ namespace {
 
 static std::string PathToDirectory(const std::string& path) {
   if (path.rfind("s3://", 0) == 0) {
-    int t = path.find_last_of('?');
+    size_t t = path.find_last_of('?');
     std::string prefix = path.substr(0, t);
     std::string suffix = path.substr(t);
     const size_t last_slash_idx = prefix.rfind('/');
@@ -1257,8 +1244,8 @@ class GraphInfo::Impl {
   std::string prefix_;
   std::shared_ptr<const InfoVersion> version_;
   std::unordered_map<std::string, std::string> extra_info_;
-  std::unordered_map<std::string, int> vtype_to_index_;
-  std::unordered_map<std::string, int> etype_to_index_;
+  std::unordered_map<std::string, size_t> vtype_to_index_;
+  std::unordered_map<std::string, size_t> etype_to_index_;
 };
 
 GraphInfo::GraphInfo(
@@ -1290,46 +1277,44 @@ const std::unordered_map<std::string, std::string>& 
GraphInfo::GetExtraInfo()
 
 std::shared_ptr<VertexInfo> GraphInfo::GetVertexInfo(
     const std::string& type) const {
-  int i = GetVertexInfoIndex(type);
-  return i == -1 ? nullptr : impl_->vertex_infos_[i];
+  auto i = GetVertexInfoIndex(type);
+  return i.has_value() ? impl_->vertex_infos_[i.value()] : nullptr;
 }
 
-int GraphInfo::GetVertexInfoIndex(const std::string& type) const {
+std::optional<size_t> GraphInfo::GetVertexInfoIndex(
+    const std::string& type) const {
   return LookupKeyIndex(impl_->vtype_to_index_, type);
 }
 
 std::shared_ptr<EdgeInfo> GraphInfo::GetEdgeInfo(
     const std::string& src_type, const std::string& edge_type,
     const std::string& dst_type) const {
-  int i = GetEdgeInfoIndex(src_type, edge_type, dst_type);
-  return i == -1 ? nullptr : impl_->edge_infos_[i];
+  auto i = GetEdgeInfoIndex(src_type, edge_type, dst_type);
+  return i.has_value() ? impl_->edge_infos_[i.value()] : nullptr;
 }
 
-int GraphInfo::GetEdgeInfoIndex(const std::string& src_type,
-                                const std::string& edge_type,
-                                const std::string& dst_type) const {
+std::optional<size_t> GraphInfo::GetEdgeInfoIndex(
+    const std::string& src_type, const std::string& edge_type,
+    const std::string& dst_type) const {
   std::string edge_key = ConcatEdgeTriple(src_type, edge_type, dst_type);
   return LookupKeyIndex(impl_->etype_to_index_, edge_key);
 }
 
-int GraphInfo::VertexInfoNum() const {
-  return static_cast<int>(impl_->vertex_infos_.size());
-}
+size_t GraphInfo::VertexInfoNum() const { return impl_->vertex_infos_.size(); }
 
-int GraphInfo::EdgeInfoNum() const {
-  return static_cast<int>(impl_->edge_infos_.size());
-}
+size_t GraphInfo::EdgeInfoNum() const { return impl_->edge_infos_.size(); }
 
 const std::shared_ptr<VertexInfo> GraphInfo::GetVertexInfoByIndex(
-    int index) const {
-  if (index < 0 || index >= static_cast<int>(impl_->vertex_infos_.size())) {
+    size_t index) const {
+  if (index >= impl_->vertex_infos_.size()) {
     return nullptr;
   }
   return impl_->vertex_infos_[index];
 }
 
-const std::shared_ptr<EdgeInfo> GraphInfo::GetEdgeInfoByIndex(int index) const 
{
-  if (index < 0 || index >= static_cast<int>(impl_->edge_infos_.size())) {
+const std::shared_ptr<EdgeInfo> GraphInfo::GetEdgeInfoByIndex(
+    size_t index) const {
+  if (index >= impl_->edge_infos_.size()) {
     return nullptr;
   }
   return impl_->edge_infos_[index];
@@ -1350,7 +1335,7 @@ Result<std::shared_ptr<GraphInfo>> GraphInfo::AddVertex(
   if (vertex_info == nullptr) {
     return Status::Invalid("vertex info is nullptr");
   }
-  if (GetVertexInfoIndex(vertex_info->GetType()) != -1) {
+  if (GetVertexInfoIndex(vertex_info->GetType()).has_value()) {
     return Status::Invalid("vertex info already exists");
   }
   return std::make_shared<GraphInfo>(
@@ -1363,13 +1348,12 @@ Result<std::shared_ptr<GraphInfo>> 
GraphInfo::RemoveVertex(
   if (vertex_info == nullptr) {
     return Status::Invalid("vertex info is nullptr");
   }
-  int idx = GetVertexInfoIndex(vertex_info->GetType());
-  if (idx == -1) {
+  auto idx = GetVertexInfoIndex(vertex_info->GetType());
+  if (!idx.has_value()) {
     return Status::Invalid("vertex info not found");
   }
   return std::make_shared<GraphInfo>(
-      impl_->name_,
-      RemoveVectorElement(impl_->vertex_infos_, static_cast<size_t>(idx)),
+      impl_->name_, RemoveVectorElement(impl_->vertex_infos_, idx.value()),
       impl_->edge_infos_, impl_->labels_, impl_->prefix_, impl_->version_,
       impl_->extra_info_);
 }
@@ -1380,7 +1364,8 @@ Result<std::shared_ptr<GraphInfo>> GraphInfo::AddEdge(
     return Status::Invalid("edge info is nullptr");
   }
   if (GetEdgeInfoIndex(edge_info->GetSrcType(), edge_info->GetEdgeType(),
-                       edge_info->GetDstType()) != -1) {
+                       edge_info->GetDstType())
+          .has_value()) {
     return Status::Invalid("edge info already exists");
   }
   return std::make_shared<GraphInfo>(
@@ -1394,15 +1379,15 @@ Result<std::shared_ptr<GraphInfo>> 
GraphInfo::RemoveEdge(
   if (edge_info == nullptr) {
     return Status::Invalid("edge info is nullptr");
   }
-  int idx = GetEdgeInfoIndex(edge_info->GetSrcType(), edge_info->GetEdgeType(),
-                             edge_info->GetDstType());
-  if (idx == -1) {
+  auto idx = GetEdgeInfoIndex(edge_info->GetSrcType(), 
edge_info->GetEdgeType(),
+                              edge_info->GetDstType());
+  if (!idx.has_value()) {
     return Status::Invalid("edge info not found");
   }
   return std::make_shared<GraphInfo>(
       impl_->name_, impl_->vertex_infos_,
-      RemoveVectorElement(impl_->edge_infos_, static_cast<size_t>(idx)),
-      impl_->labels_, impl_->prefix_, impl_->version_, impl_->extra_info_);
+      RemoveVectorElement(impl_->edge_infos_, idx.value()), impl_->labels_,
+      impl_->prefix_, impl_->version_, impl_->extra_info_);
 }
 
 std::shared_ptr<GraphInfo> CreateGraphInfo(
diff --git a/cpp/src/graphar/graph_info.h b/cpp/src/graphar/graph_info.h
index 32c3de2d..d5f6d66b 100644
--- a/cpp/src/graphar/graph_info.h
+++ b/cpp/src/graphar/graph_info.h
@@ -20,6 +20,7 @@
 #pragma once
 
 #include <memory>
+#include <optional>
 #include <string>
 #include <unordered_map>
 #include <vector>
@@ -256,7 +257,7 @@ class VertexInfo {
    *
    * @return The number of property groups of the vertex.
    */
-  int PropertyGroupNum() const;
+  size_t PropertyGroupNum() const;
 
   /**
    * Get the property groups of the vertex.
@@ -278,7 +279,7 @@ class VertexInfo {
    * @param index The index of the property group.
    * @return property group may be nullptr if the index is out of range.
    */
-  std::shared_ptr<PropertyGroup> GetPropertyGroupByIndex(int index) const;
+  std::shared_ptr<PropertyGroup> GetPropertyGroupByIndex(size_t index) const;
 
   /**
    * Get the data type of the specified property.
@@ -555,7 +556,7 @@ class EdgeInfo {
   /**
    * @brief Get the number of property groups.
    */
-  int PropertyGroupNum() const;
+  size_t PropertyGroupNum() const;
 
   /**
    * @brief Get the property groups.
@@ -578,7 +579,7 @@ class EdgeInfo {
    * @param index The index of the property group.
    * @return Property group may be nullptr if the index is out of range.
    */
-  std::shared_ptr<PropertyGroup> GetPropertyGroupByIndex(int index) const;
+  std::shared_ptr<PropertyGroup> GetPropertyGroupByIndex(size_t index) const;
 
   /**
    * @brief Get the file path for the number of vertices.
@@ -869,25 +870,25 @@ class GraphInfo {
   /**
    * @brief Get the vertex info index with the given type.
    */
-  int GetVertexInfoIndex(const std::string& type) const;
+  std::optional<size_t> GetVertexInfoIndex(const std::string& type) const;
 
   /**
    * @brief Get the edge info index with the given source vertex type, edge
    * type, and destination type.
    */
-  int GetEdgeInfoIndex(const std::string& src_type,
-                       const std::string& edge_type,
-                       const std::string& dst_type) const;
+  std::optional<size_t> GetEdgeInfoIndex(const std::string& src_type,
+                                         const std::string& edge_type,
+                                         const std::string& dst_type) const;
 
   /**
    * @brief Get the number of vertex infos.
    */
-  int VertexInfoNum() const;
+  size_t VertexInfoNum() const;
 
   /**
    * @brief Get the number of edge infos.
    */
-  int EdgeInfoNum() const;
+  size_t EdgeInfoNum() const;
 
   /**
    * @brief Get the vertex info at the specified index.
@@ -895,7 +896,7 @@ class GraphInfo {
    * @param index The index of the vertex info.
    * @return vertex info may be nullptr if the index is out of range.
    */
-  const std::shared_ptr<VertexInfo> GetVertexInfoByIndex(int index) const;
+  const std::shared_ptr<VertexInfo> GetVertexInfoByIndex(size_t index) const;
 
   /**
    * @brief Get the edge info at the specified index.
@@ -903,7 +904,7 @@ class GraphInfo {
    * @param index The index of the edge info.
    * @return edge info may be nullptr if the index is out of range.
    */
-  const std::shared_ptr<EdgeInfo> GetEdgeInfoByIndex(int index) const;
+  const std::shared_ptr<EdgeInfo> GetEdgeInfoByIndex(size_t index) const;
 
   /**
    * @brief Get the vertex infos of graph info
diff --git a/rust/src/ffi.rs b/rust/src/ffi.rs
index 66a9c712..9855a8ad 100644
--- a/rust/src/ffi.rs
+++ b/rust/src/ffi.rs
@@ -255,14 +255,12 @@ pub(crate) mod graphar {
         fn version(&self) -> &SharedPtr<ConstInfoVersion>;
         fn GetLabels(&self) -> &CxxVector<CxxString>;
 
-        // TODO: upstream C++ uses `int` for this return type; prefer 
fixed-width.
-        fn PropertyGroupNum(&self) -> i32;
+        fn PropertyGroupNum(&self) -> usize;
 
         fn GetPropertyGroups(&self) -> &CxxVector<SharedPropertyGroup>;
         fn GetPropertyGroup(&self, property_name: &CxxString) -> 
SharedPtr<PropertyGroup>;
 
-        // TODO: upstream C++ uses `int` for this parameter; prefer 
fixed-width.
-        fn GetPropertyGroupByIndex(&self, index: i32) -> 
SharedPtr<PropertyGroup>;
+        fn GetPropertyGroupByIndex(&self, index: usize) -> 
SharedPtr<PropertyGroup>;
 
         #[namespace = "graphar_rs"]
         fn create_vertex_info(
@@ -323,10 +321,10 @@ pub(crate) mod graphar {
         fn HasAdjacentListType(&self, adj_list_type: AdjListType) -> bool;
         fn GetAdjacentList(&self, adj_list_type: AdjListType) -> 
SharedPtr<AdjacentList>;
 
-        fn PropertyGroupNum(&self) -> i32;
+        fn PropertyGroupNum(&self) -> usize;
         fn GetPropertyGroups(&self) -> &CxxVector<SharedPropertyGroup>;
         fn GetPropertyGroup(&self, property: &CxxString) -> 
SharedPtr<PropertyGroup>;
-        fn GetPropertyGroupByIndex(&self, index: i32) -> 
SharedPtr<PropertyGroup>;
+        fn GetPropertyGroupByIndex(&self, index: usize) -> 
SharedPtr<PropertyGroup>;
 
         #[namespace = "graphar_rs"]
         #[allow(clippy::too_many_arguments)]
diff --git a/rust/src/info/edge_info.rs b/rust/src/info/edge_info.rs
index 1862da25..0ef70f53 100644
--- a/rust/src/info/edge_info.rs
+++ b/rust/src/info/edge_info.rs
@@ -201,8 +201,7 @@ impl EdgeInfo {
 
     /// Return the number of property groups.
     ///
-    /// TODO: upstream C++ uses `int` for this return type; prefer fixed-width.
-    pub fn property_group_num(&self) -> i32 {
+    pub fn property_group_num(&self) -> usize {
         self.0.PropertyGroupNum()
     }
 
@@ -244,8 +243,7 @@ impl EdgeInfo {
     ///
     /// Returns `None` if the index is out of range.
     ///
-    /// TODO: upstream C++ uses `int` for this parameter; prefer fixed-width.
-    pub fn property_group_by_index(&self, index: i32) -> Option<PropertyGroup> 
{
+    pub fn property_group_by_index(&self, index: usize) -> 
Option<PropertyGroup> {
         let sp = self.0.GetPropertyGroupByIndex(index);
         if sp.is_null() {
             None
@@ -500,7 +498,7 @@ mod tests {
         assert!(edge_info.property_group("missing").is_none());
         assert!(edge_info.property_group_by_index(0).is_some());
         assert!(edge_info.property_group_by_index(1).is_none());
-        assert!(edge_info.property_group_by_index(-1).is_none());
+        assert!(edge_info.property_group_by_index(usize::MAX).is_none());
     }
 
     #[test]
diff --git a/rust/src/info/vertex_info.rs b/rust/src/info/vertex_info.rs
index 0acd1b53..10b93ad9 100644
--- a/rust/src/info/vertex_info.rs
+++ b/rust/src/info/vertex_info.rs
@@ -122,8 +122,7 @@ impl VertexInfo {
 
     /// Return the number of property groups.
     ///
-    /// TODO: upstream C++ uses `int` for this return type; prefer fixed-width.
-    pub fn property_group_num(&self) -> i32 {
+    pub fn property_group_num(&self) -> usize {
         self.0.PropertyGroupNum()
     }
 
@@ -170,10 +169,9 @@ impl VertexInfo {
     /// If you only need a borrowed reference and want bounds checking, prefer
     /// [`VertexInfo::property_groups_cxx`] and `cxx::CxxVector::get`, or
     /// [`VertexInfo::property_groups_iter`] with `nth`.
-    /// TODO: upstream C++ uses `int` for this parameter; prefer fixed-width.
     ///
     /// Returns `None` if the index is out of range.
-    pub fn property_group_by_index(&self, index: i32) -> Option<PropertyGroup> 
{
+    pub fn property_group_by_index(&self, index: usize) -> 
Option<PropertyGroup> {
         let sp = self.0.GetPropertyGroupByIndex(index);
         if sp.is_null() {
             None
@@ -464,7 +462,7 @@ mod tests {
         assert!(by_index.has_property("id"));
 
         assert!(vertex_info.property_group_by_index(1).is_none());
-        assert!(vertex_info.property_group_by_index(-1).is_none());
+        assert!(vertex_info.property_group_by_index(usize::MAX).is_none());
     }
 
     #[test]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to