- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
<分区>
我有一个集合,每个集合的元素都有值,我想按值将元素尽可能均匀地分布在 N 个片段上。
我试过用scala代码完成如下结果,一直没找到好方法,很容易死循环
像这样:
Map("table1"->100,"table2"->500,"table3"->20000,"table4"->10,"table5"->1000,"table6"->200,"table7"->10000)
对于4件,我希望得到尽可能平均的结果。
Map("table7"->10000)
Map("table3"->20000)
Map("table1"->100,"table2"->500,"table4"->10,"table4"->10,"table5"->1000,"table6"->200)
Map()
或者,很完美
Map("table7"->10000)
Map("table3"->20000)
Map("table1"->100,"table2"->500,"table4"->10,"table4"->10,"table6"->200)
Map("table5"->1000)
我用了@Krzysztof Atłasik的代码,得到的结果是重复的。10 个桶。公式数据为:
val testMap=Map("test_7d_all_qr "->1,"test_daily_advertise_position "->1,"test_7d_province "->94,"test_city_statistics "->34916,"test_30days_page_view "->11,"test_30days_ad_anomaly_auth_analyze "->26,"tt_user_grouping "->1,"oauth_refresh_tokens "->42,"tt_daily_share "->4476,"test_ad_anomaly_ip_analyze "->148,"test_7d_ad_anomaly_time_analyze "->15,"share_tool_template "->1,"test_30days_visit_duration "->70,"tt_qr_group_01 "->1,"tt_seven_user_tmp "->35890,"test_qr_code_statistics_temporary "->1,"tt_cms_scene "->1,"test_30days_terminal_analysis "->1406,"test_7d_terminal_analysis "->765,"test_7d_single_scene "->51,"test_30days_single_scene "->77,"test_monitor_daily_new_user "->1,"tt_ad_authorize "->1,"tt_sdk_version_appcount "->1,"test_ad_anomaly_auth_analyze "->428,"tt_attribute_relationship "->1,"test_7d_page_view "->9,"tt_ad_user_info "->1,"phone_model "->1,"share_tool_var "->1,"share_tool_type_template "->1,"tt_stay_logs_link "->8,"test_advertise_home_hour "->4,"test_monitor_hourly "->1,"test_7d_phonebrand "->71,"tt_cms_system "->1,"test_7d_city_statistics "->297,"test_link_cheat_protect "->1,"test_daily_advertise_link "->1,"test_30days_trend_analysis "->17,"tt_cms_log "->1,"test_hourly_advertise_position "->6,"push_join_info "->1,"test_monitor_daily_app "->5,"test_7d_event "->491,"cms_boss_words "->1,"test_daily_error "->13903,"test_user_activity "->569,"tt_event "->127,"test_link_summary_hour "->290,"test_7d_single_qr_group "->1,"tt_sdk_log "->1,"tt_code "->42,"test_page_view "->11689,"tt_7d_device_statistics "->709,"test_7d_ad_anomaly_ip_analyze "->15,"cms_wx_data "->1,"tt_sdk_version_apps "->311,"test_qr_code_statistics "->138,"test_daily_link "->709,"test_30days_event "->974,"test_7d_error "->1,"test_30days_city_statistics "->527,"tt_link_trace "->8,"test_7d_single_position "->1,"test_30days_single_link "->5,"test_daily_event "->33480,"tt_share_page "->53,"tt_30days_hierarchy_share "->1,"tt_stay_logs "->17149,"test_dailyshare_gender "->282,"test_hourly_advertise_media "->6,"test_monitor_daily_link "->4,"tt_device_statistics "->66629,"oauth_authorization_codes "->73,"test_ad_anomaly_all_analyze "->5488,"test_30days_userShare_top10 "->943,"test_daily_funnel "->782,"oauth_scopes "->1,"top100070922 "->0,"test_7d_userShare_top10 "->639,"tt_hierarchy_share "->148,"oauth_clients "->1,"user_phone "->0,"tt_sms_queue "->2,"tt_cms_article "->1,"test_monitor_daily "->1,"cms_source_type "->1,"test_30days_entrance_page "->11,"test_30days_ad_anomaly_all_analyze "->636,"oauth_jwt "->1,"tt_cms_user "->1,"tt_ci_sessions "->38,"test_7d_link_monitor "->1,"test_daily_link_monitor "->2717,"test_hourly_qr_group "->239,"tt_7d_hierarchy_share "->1,"test_30days_event_paras "->1,"tt_event_link_funnel "->2,"test_blackIP_setting "->1,"test_visit_duration "->2476,"tt_qr_group "->19,"test_hourly_scene "->41057,"test_30days_ad_anomaly_time_analyze "->26,"test_hourly_scene_group "->24908,"tt_smartLink_dict_name "->1,"test_scene_statistics "->7868,"test_30days_single_entrance_page "->59,"test_online_status "->1,"convert_path "->1,"user_group_funnel_daily "->7,"test_daily_media "->238,"test_grey_ak "->1,"cms_market "->1,"test_dailyshare_top10 "->10329,"test_hourly_qr "->334,"test_monitor_daily_trend "->8,"test_dailyshare_source "->224,"test_ad_anomaly_time_analyze "->158,"test_30days_scene_group "->34,"test_hourly_share_summary "->2895,"test_30days_single_page_view "->107,"service_user_view "->1,"tt_funnel "->1,"test_30days_single_qr_group "->1,"test_monitor_hourly_link "->12,"test_30days_error "->1,"test_daily_scene_group "->3702,"test_smartLink_day_analysis "->5770,"tt_prevent_cheat "->1,"test_hourly_advertise_link "->8,"tt_wechat_user_bind "->440049,"user_apps "->110,"test_dailyshare_page "->1394,"test_link_summary "->57,"test_smartLink_summary_analysis "->352,"share_tool_code "->1,"test_7d_trend_analysis "->15,"test_7d_event_paras "->1,"tt_sdk_history "->1,"tt_mini_code_authorize "->1,"test_visit_depth "->1852,"test_daily_entrance_page "->1254,"tt_private_construct_info "->1,"test_monitor_hourly_trend "->14,"tt_user_etl "->12914,"test_7d_scene_group "->26,"test_30days_link_summary "->1,"test_7d_visit_depth "->43,"tt_task "->1,"tt_code_share "->29,"tt_authorization "->1,"test_daily_advertise_media "->1,"share_tool_user_template "->1,"tt_30days_device_statistics "->1301,"tt_code_tool "->21,"test_30days_single_media "->2,"tt_scene_link "->1,"tt_code_sem "->2,"tt_stay_logs_media "->4,"tt_mini_radio "->1,"tt_sdk_notice "->1,"test_entrance_page "->5209,"test_terminal_analysis "->91350,"test_7d_single_entrance_page "->39,"test_7d_visit_duration "->57,"cms_analy_bind "->1,"test_30days_link_monitor "->1,"test_hourly_trend_analysis_debug "->1,"test_advertise_home "->1,"tt_stay_logs_position "->4,"test_30days_single_position "->1,"tt_smartLink_dict "->114,"test_ad_anomaly_all_analyze_hour "->1,"test_monitor_hourly_qr "->1,"test_smartLink_hour_analysis "->39287,"test_hourly_position "->843,"tt_cms_scene_type "->1,"test_dailyshare_city "->2915,"test_operation_log "->1,"oauth_access_tokens "->42,"share_tool_type "->1,"test_hourly_media "->1432,"tt_mini_routine_push "->6,"test_daily_position "->92,"test_app_summary "->1,"test_trend_analysis_debug "->1,"test_daily_phonebrand "->6565,"test_daily_share_summary "->371,"test_third_setup "->1,"user_app_relations "->20,"test_7d_single_link "->2,"tt_field_mapping "->1,"test_event_paras "->684271,"test_7d_entrance_page "->9,"test_dailyshare_user "->548969,"test_region_statistics "->11658,"test_7d_ad_anomaly_all_analyze "->396,"test_30days_visit_depth "->53,"tt_authorize "->6,"test_30days_province "->148,"tt_ad_activity_hourly "->714,"test_7d_link_summary "->1,"oauth_users "->1,"test_monitor_daily_qr "->1,"test_30days_phonebrand "->117,"test_7d_single_media "->1,"tt_db_split "->1,"test_30days_ad_anomaly_ip_analyze "->25,"service_user "->1,"test_monitor_hourly_share "->34,"test_hourly_trend_analysis "->16825,"test_30days_all_qr "->1,"test_trend_analysis "->2196,"aladdin_user "->4,"test_30days_single_qr "->3,"test_daily_page_view "->1295,"tt_stay_logs_bak "->250,"test_hourly_link "->3199,"tt_media "->3,"test_7d_ad_anomaly_auth_analyze "->15,"test_7d_single_qr "->1,"test_daily_qr_group "->37,"test_7d_single_page_view "->70,"user_feedback "->1,"test_user_activity_details "->2486,"test_monitor_daily_share "->1)
我得到了这个结果
Map(test_event_paras -> 684271)
Map(test_dailyshare_user -> 548969)
Map(tt_wechat_user_bind -> 440049)
Map(test_terminal_analysis -> 91350)
Map(test_daily_qr_group -> 37, tt_stay_logs_bak -> 250, test_hourly_link -> 3199, test_7d_single_page_view -> 70, tt_device_statistics -> 66629, test_monitor_hourly_trend -> 14, test_smartLink_summary_analysis -> 352, test_7d_single_scene -> 51, test_user_activity -> 569, tt_hierarchy_share -> 148, test_daily_page_view -> 1295, tt_smartLink_dict -> 114, test_trend_analysis -> 2196, test_30days_trend_analysis -> 17, test_7d_terminal_analysis -> 765)
Map(aladdin_user -> 4, test_30days_ad_anomaly_ip_analyze -> 25, tt_stay_logs_bak -> 250, test_30days_scene_group -> 34, test_hourly_link -> 3199, test_7d_single_page_view -> 70, tt_device_statistics -> 66629, test_smartLink_summary_analysis -> 352, test_7d_single_scene -> 51, test_user_activity -> 569, tt_hierarchy_share -> 148, test_daily_page_view -> 1295, tt_smartLink_dict -> 114, test_advertise_home_hour -> 4, test_trend_analysis -> 2196, test_7d_terminal_analysis -> 765)
Map(aladdin_user -> 4, test_30days_ad_anomaly_ip_analyze -> 25, tt_stay_logs_bak -> 250, test_30days_scene_group -> 34, test_hourly_link -> 3199, test_7d_single_page_view -> 70, tt_device_statistics -> 66629, test_smartLink_summary_analysis -> 352, test_7d_single_scene -> 51, test_user_activity -> 569, tt_hierarchy_share -> 148, test_daily_page_view -> 1295, tt_smartLink_dict -> 114, test_trend_analysis -> 2196, test_7d_terminal_analysis -> 765, tt_media -> 3)
Map(aladdin_user -> 4, test_30days_ad_anomaly_ip_analyze -> 25, tt_stay_logs_bak -> 250, test_30days_scene_group -> 34, test_hourly_link -> 3199, test_7d_single_page_view -> 70, tt_device_statistics -> 66629, test_smartLink_summary_analysis -> 352, test_7d_single_scene -> 51, test_user_activity -> 569, tt_hierarchy_share -> 148, test_daily_page_view -> 1295, tt_smartLink_dict -> 114, test_trend_analysis -> 2196, test_7d_terminal_analysis -> 765, tt_event_link_funnel -> 2)
Map(aladdin_user -> 4, test_30days_ad_anomaly_ip_analyze -> 25, tt_stay_logs_bak -> 250, test_30days_scene_group -> 34, test_hourly_link -> 3199, test_7d_single_page_view -> 70, tt_device_statistics -> 66629, test_smartLink_summary_analysis -> 352, test_7d_single_scene -> 51, test_user_activity -> 569, tt_hierarchy_share -> 148, test_daily_page_view -> 1295, tt_smartLink_dict -> 114, test_trend_analysis -> 2196, test_7d_terminal_analysis -> 765, tt_sdk_history -> 1)
Map(aladdin_user -> 4, test_30days_ad_anomaly_ip_analyze -> 25, tt_stay_logs_bak -> 250, test_30days_scene_group -> 34, test_hourly_link -> 3199, test_7d_single_page_view -> 70, tt_device_statistics -> 66629, user_phone -> 0, test_smartLink_summary_analysis -> 352, test_7d_single_scene -> 51, test_user_activity -> 569, tt_hierarchy_share -> 148, test_daily_page_view -> 1295, top100070922 -> 0, tt_smartLink_dict -> 114, test_trend_analysis -> 2196, test_7d_terminal_analysis -> 765)
我按照Krzysztof Atłasik的方式重写了一个方法, 结果正确。
def distributeMy(elements: Map[String, Long], bucketCount: Long) = {
implicit val ordering: Ordering[(Long, Map[String, Long])] = Ordering.by(-_._1)
val map = elements.toList.sortBy(-_._2)
var bucket =new mutable.TreeSet[(Long,Map[String,Long])]
map.foreach{
case (k:String,v:Long) =>{
if(bucket.size < bucketCount){
bucket.add((v,Map(k->v)))
}
else{
val element = bucket.last
bucket.remove(bucket.last)
bucket.add((element._1 + v ,element._2 ++ Map(k->v) ))
}
}
}
bucket.toSet
}
编辑:我似乎问错了这个问题。 我正在尝试寻找一种方法来查询一个集合是否在另一个集合中可用。例如: SELECT * FROM something WHERE (1, 3) IN (1, 2, 3, 4
这两种方法似乎 produce the same results ,但我一直很难真正说服人们第二种方法有效,因为它显然并不为人所知。 // Create some data var foo = { '
我一直在学习Kotlin,并且遇到过Collections API。在Kotlin之前,我一直在学习Java,并且我知道Java中有很多不同类型的Collections API。例如,我们使用List
为什么我会得到不同的行为: Collection col2 = new ArrayList(col); 集合 col2 = new ArrayList(); col2.addAll(col) 我正在与
所以我有一个代表专辑信息的 JSON 对象。给定“function updateRecords(id, prop, value)”我希望能够更新每个条目。正确的完成代码如下。 我得到了指示,粗体部分,
我想存储一个对象集合,这些对象根据它们所代表的值进行键控。这些键可以重复。例如: [4] => Bob [5] => Mary [5] => Sue [9] => Steve [10] =>
在检查 ArrayList API 时,我注意到一些看起来很奇怪的东西。 确实,这里是 ArrayList 构造函数实现,其中 Collection 作为参数传递: public ArrayList(
我正在为 API 编写一个 swagger 定义文件。 API 是用于 GET 请求的 /path/to/my/api: get: summary: My Custom API d
我知道scala.collection包中有两个非常有用的对象,可以帮助我们实现这个目标: JavaConverters(如果我想明确说明并准确说明我要转换的内容) JavaConversions(如
我已经阅读了无数其他帖子,但似乎无法弄清楚发生了什么,所以是时候寻求帮助了。 我正在尝试将包含集合的域实体映射到也包含集合的 dtos。 这是一个原始示例; (我提前为代码墙道歉,我尽量保持简短):
我正在创建一个具有 ArrayList 的类,因此当我调用构造函数时,它会初始化该数组: public class ElementsList { private ArrayList list;
我正在阅读事件指南和指南的开头,它说: You can also add an event listener to any element in the this.$ collection using
我是 Python 新手,想知道如何使用键在字典中存储不同数据类型的列表 例如 - {[Key1,int1,int1,String1] , [Key2,int2,int2,String2], [Key
int[] mylist = { 2, 4, 5 }; IEnumerable list1 = mylist; list1.ToList().Add(1); // why 1 does not get
我在 UI 表单中的每一行之后将以下内容添加到 HashMap 集合中 声明 Map> map = new HashMap>(); List valSetOne = new ArrayList();
我正在开发我的第一个 Java 项目,我有一个问题。问题应该很简单(虽然代码不是那么短,但没有理由被吓倒:))。我创建了一个基本的角色扮演游戏,并且有一个定义每个角色的抽象类“Character”。在
我正在开发一款应用程序,可以为用户收集推文、Facebook 状态和 Facebook 照片。目前,用户确切地设定了他们希望这种收获发生的时间和时间,并且蜘蛛会在此期间拉取数据。 when 和 to
有谁知道在 C# 中是否有与 Java 的 Set 集合等效的好方法?我知道您可以通过填充但忽略值来使用 Dictionary 或 HashTable 在某种程度上模仿集合,但这不是一种非常优雅的方式
EXISTS 该函数返回 集合中第一个元素的索引,如果集合为空,返回NULLNULLNULL Collecti
RDF集合是通过属性 rdf:parseType="Collection" 来描述仅包含指定成员的组 rdf:parseType="Collection" 属
我是一名优秀的程序员,十分优秀!