当前位置: 首页>>代码示例>>C++>>正文


C++ MovieData::find_rating_by_id方法代码示例

本文整理汇总了C++中MovieData::find_rating_by_id方法的典型用法代码示例。如果您正苦于以下问题:C++ MovieData::find_rating_by_id方法的具体用法?C++ MovieData::find_rating_by_id怎么用?C++ MovieData::find_rating_by_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MovieData的用法示例。


在下文中一共展示了MovieData::find_rating_by_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: append_user_batch

/*
 * load and write a batch of users
 */
void IBBL_LargeFile::append_user_batch(int_set::iterator& batch_start,
                                       int_set::iterator& batch_end,
                                       int& offset, 
                                       ofstream& user_offset_file,
                                       ofstream& user_file)
{
  if (batch_start == batch_end)
    return;
  
  int_ur_mmap user_map;

  /* go through every movie file */
  MovieData d;
  movie_rating r;
  user_rating u;
  int uid;
  
  for (int id = 1; id <= NUM_MOVIES; ++id)
  {
    // load the movie
    d.load_from_binary(this, id);

    // go through each user
    for (int_set::iterator itr = batch_start; itr != batch_end; ++itr)
    {
      uid = *itr;
      if (d.find_rating_by_id(uid, &r))
      {
        // convert the rating to a user rating and add to that user's list
        u.rating = r.rating;
        u.movie_id = id;
        u.year = r.year;
        u.month = r.month;
        u.day = r.day;
        user_map.insert(make_pair(uid, u));
      }
    }  
  }  
  
  /* save each user to the file */
  int num_user_ratings;
  int_ur_mmap::iterator begin, end;
  for (int_set::iterator itr = batch_start; itr != batch_end; ++itr)
  {
    uid = *itr;
    pair<int_ur_mmap::iterator,int_ur_mmap::iterator> ret = user_map.equal_range(uid);

    // write the number of ratings
    num_user_ratings = user_map.count(uid);
    user_file.write((char*)&num_user_ratings, 4);

    // write and increment the offset
    user_offset_file.write((char*)&uid, 4);
    user_offset_file.write((char*)&offset, 4);
    offset += 4 + num_user_ratings * sizeof(user_rating);

    // write each rating
    begin = ret.first;
    end = ret.second;
    for (int_ur_mmap::iterator u_itr = begin; u_itr != end; ++u_itr)
    {
      u = u_itr->second;
      user_file.write((char*)&u, sizeof(user_rating));
    }
  }
    
}
开发者ID:andyhebear,项目名称:ymfas,代码行数:70,代码来源:ibbl_largefile.cpp


注:本文中的MovieData::find_rating_by_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。