.. _stdlib_algorithm: ======================= 杂项算法 ======================= .. include:: detail/algorithm.rst ALGORITHM 模块公开了各种数组作算法的集合。 所有函数和交易品种都在 “algorithm” 模块中,使用 require 来访问它。 :: require daslib/algorithm ++++++ Search ++++++ * :ref:`lower_bound (a:array\ const;f:int const;l:int const;val:TT const -&) : auto ` * :ref:`lower_bound (a:array\ const;val:TT const -&) : auto ` * :ref:`lower_bound (a:array\ const;f:int const;l:int const;value:TT const -&;less:block\<(a:TT const -&;b:TT const -&):bool\> const) : auto ` * :ref:`lower_bound (a:array\ const;value:TT const -&;less:block\<(a:TT const -&;b:TT const -&):bool\> const) : auto ` * :ref:`binary_search (a:array\ const;val:TT const -&) : auto ` * :ref:`binary_search (a:array\ const;f:int const;last:int const;val:TT const -&) : auto ` * :ref:`binary_search (a:array\ const;val:TT const -&;less:block\<(a:TT const -&;b:TT const -&):bool\> const) : auto ` * :ref:`binary_search (a:array\ const;f:int const;last:int const;val:TT const -&;less:block\<(a:TT const -&;b:TT const -&):bool\> const) : auto ` * :ref:`lower_bound (a:auto const;f:int const;l:int const;val:auto const) : auto ` * :ref:`lower_bound (a:auto const;val:auto const) : auto ` * :ref:`lower_bound (a:auto const;f:int const;l:int const;val:auto(TT) const;less:block\<(a:TT const -&;b:TT const -&):bool\> const) : auto ` * :ref:`lower_bound (a:auto const;val:auto(TT) const;less:block\<(a:TT const -&;b:TT const -&):bool\> const) : auto ` * :ref:`binary_search (a:auto const;val:auto const) : auto ` * :ref:`binary_search (a:auto const;f:int const;last:int const;val:auto const) : auto ` * :ref:`binary_search (a:auto const;val:auto(TT) const;less:block\<(a:TT const -&;b:TT const -&):bool\> const) : auto ` * :ref:`binary_search (a:auto const;f:int const;last:int const;val:auto(TT) const;less:block\<(a:TT const -&;b:TT const -&):bool\> const) : auto ` .. _function-_at_algorithm_c__c_lower_bound_C1_ls_Y_ls_TT_gr_._gr_A_Ci_Ci_CY_ls_TT_gr_L: .. das:function:: lower_bound(a: array const; f: int const; l: int const; val: TT const) lower_bound returns auto +--------+---------------------+ +argument+argument type + +========+=====================+ +a +array const+ +--------+---------------------+ +f +int const + +--------+---------------------+ +l +int const + +--------+---------------------+ +val +TT const + +--------+---------------------+ 返回一个迭代器,该迭代器指向范围 [first, last] 中的第一个元素,该元素不小于(即大于或等于)值,如果未找到此类元素,则返回 last。 .. _function-_at_algorithm_c__c_lower_bound_C1_ls_Y_ls_TT_gr_._gr_A_CY_ls_TT_gr_L: .. das:function:: lower_bound(a: array const; val: TT const) lower_bound returns auto +--------+---------------------+ +argument+argument type + +========+=====================+ +a +array const+ +--------+---------------------+ +val +TT const + +--------+---------------------+ 返回一个迭代器,该迭代器指向范围 [first, last] 中的第一个元素,该元素不小于(即大于或等于)值,如果未找到此类元素,则返回 last。 .. _function-_at_algorithm_c__c_lower_bound_C1_ls_Y_ls_TT_gr_._gr_A_Ci_Ci_CY_ls_TT_gr_L_CN_ls_a;b_gr_0_ls_CY_ls_TT_gr_L;CY_ls_TT_gr_L_gr_1_ls_b_gr__builtin_: .. das:function:: lower_bound(a: array const; f: int const; l: int const; value: TT const; less: block<(a:TT const;b:TT const):bool> const) lower_bound returns auto +--------+-----------------------------------------+ +argument+argument type + +========+=========================================+ +a +array const + +--------+-----------------------------------------+ +f +int const + +--------+-----------------------------------------+ +l +int const + +--------+-----------------------------------------+ +value +TT const + +--------+-----------------------------------------+ +less +block<(a:TT const;b:TT const):bool> const+ +--------+-----------------------------------------+ 返回一个迭代器,该迭代器指向范围 [first, last] 中的第一个元素,该元素不小于(即大于或等于)值,如果未找到此类元素,则返回 last。 .. _function-_at_algorithm_c__c_lower_bound_C1_ls_Y_ls_TT_gr_._gr_A_CY_ls_TT_gr_L_CN_ls_a;b_gr_0_ls_CY_ls_TT_gr_L;CY_ls_TT_gr_L_gr_1_ls_b_gr__builtin_: .. das:function:: lower_bound(a: array const; value: TT const; less: block<(a:TT const;b:TT const):bool> const) lower_bound returns auto +--------+-----------------------------------------+ +argument+argument type + +========+=========================================+ +a +array const + +--------+-----------------------------------------+ +value +TT const + +--------+-----------------------------------------+ +less +block<(a:TT const;b:TT const):bool> const+ +--------+-----------------------------------------+ 返回一个迭代器,该迭代器指向范围 [first, last] 中的第一个元素,该元素不小于(即大于或等于)值,如果未找到此类元素,则返回 last。 .. _function-_at_algorithm_c__c_binary_search_C1_ls_Y_ls_TT_gr_._gr_A_CY_ls_TT_gr_L: .. das:function:: binary_search(a: array const; val: TT const) binary_search returns auto +--------+---------------------+ +argument+argument type + +========+=====================+ +a +array const+ +--------+---------------------+ +val +TT const + +--------+---------------------+ 现在适用于所有其他类型的 .. _function-_at_algorithm_c__c_binary_search_C1_ls_Y_ls_TT_gr_._gr_A_Ci_Ci_CY_ls_TT_gr_L: .. das:function:: binary_search(a: array const; f: int const; last: int const; val: TT const) binary_search returns auto +--------+---------------------+ +argument+argument type + +========+=====================+ +a +array const+ +--------+---------------------+ +f +int const + +--------+---------------------+ +last +int const + +--------+---------------------+ +val +TT const + +--------+---------------------+ 现在适用于所有其他类型的 .. _function-_at_algorithm_c__c_binary_search_C1_ls_Y_ls_TT_gr_._gr_A_CY_ls_TT_gr_L_CN_ls_a;b_gr_0_ls_CY_ls_TT_gr_L;CY_ls_TT_gr_L_gr_1_ls_b_gr__builtin_: .. das:function:: binary_search(a: array const; val: TT const; less: block<(a:TT const;b:TT const):bool> const) binary_search returns auto +--------+-----------------------------------------+ +argument+argument type + +========+=========================================+ +a +array const + +--------+-----------------------------------------+ +val +TT const + +--------+-----------------------------------------+ +less +block<(a:TT const;b:TT const):bool> const+ +--------+-----------------------------------------+ 现在适用于所有其他类型的 .. _function-_at_algorithm_c__c_binary_search_C1_ls_Y_ls_TT_gr_._gr_A_Ci_Ci_CY_ls_TT_gr_L_CN_ls_a;b_gr_0_ls_CY_ls_TT_gr_L;CY_ls_TT_gr_L_gr_1_ls_b_gr__builtin_: .. das:function:: binary_search(a: array const; f: int const; last: int const; val: TT const; less: block<(a:TT const;b:TT const):bool> const) binary_search returns auto +--------+-----------------------------------------+ +argument+argument type + +========+=========================================+ +a +array const + +--------+-----------------------------------------+ +f +int const + +--------+-----------------------------------------+ +last +int const + +--------+-----------------------------------------+ +val +TT const + +--------+-----------------------------------------+ +less +block<(a:TT const;b:TT const):bool> const+ +--------+-----------------------------------------+ 现在适用于所有其他类型的 .. _function-_at_algorithm_c__c_lower_bound_C._Ci_Ci_C._%_ls_IsAnyArrayMacro_c_expect_any_array(a_eq_true)_gr_: .. das:function:: lower_bound(a: auto const; f: int const; l: int const; val: auto const) lower_bound returns auto +--------+-------------+ +argument+argument type+ +========+=============+ +a +auto const + +--------+-------------+ +f +int const + +--------+-------------+ +l +int const + +--------+-------------+ +val +auto const + +--------+-------------+ 返回一个迭代器,该迭代器指向范围 [first, last] 中的第一个元素,该元素不小于(即大于或等于)值,如果未找到此类元素,则返回 last。 .. _function-_at_algorithm_c__c_lower_bound_C._C._%_ls_IsAnyArrayMacro_c_expect_any_array(a_eq_true)_gr_: .. das:function:: lower_bound(a: auto const; val: auto const) lower_bound returns auto +--------+-------------+ +argument+argument type+ +========+=============+ +a +auto const + +--------+-------------+ +val +auto const + +--------+-------------+ 返回一个迭代器,该迭代器指向范围 [first, last] 中的第一个元素,该元素不小于(即大于或等于)值,如果未找到此类元素,则返回 last。 .. _function-_at_algorithm_c__c_lower_bound_C._Ci_Ci_CY_ls_TT_gr_._CN_ls_a;b_gr_0_ls_CY_ls_TT_gr_L;CY_ls_TT_gr_L_gr_1_ls_b_gr__builtin__%_ls_IsAnyArrayMacro_c_expect_any_array(a_eq_true)_gr_: .. das:function:: lower_bound(a: auto const; f: int const; l: int const; val: auto(TT) const; less: block<(a:TT const;b:TT const):bool> const) lower_bound returns auto +--------+-----------------------------------------+ +argument+argument type + +========+=========================================+ +a +auto const + +--------+-----------------------------------------+ +f +int const + +--------+-----------------------------------------+ +l +int const + +--------+-----------------------------------------+ +val +auto(TT) const + +--------+-----------------------------------------+ +less +block<(a:TT const;b:TT const):bool> const+ +--------+-----------------------------------------+ 返回一个迭代器,该迭代器指向范围 [first, last] 中的第一个元素,该元素不小于(即大于或等于)值,如果未找到此类元素,则返回 last。 .. _function-_at_algorithm_c__c_lower_bound_C._CY_ls_TT_gr_._CN_ls_a;b_gr_0_ls_CY_ls_TT_gr_L;CY_ls_TT_gr_L_gr_1_ls_b_gr__builtin__%_ls_IsAnyArrayMacro_c_expect_any_array(a_eq_true)_gr_: .. das:function:: lower_bound(a: auto const; val: auto(TT) const; less: block<(a:TT const;b:TT const):bool> const) lower_bound returns auto +--------+-----------------------------------------+ +argument+argument type + +========+=========================================+ +a +auto const + +--------+-----------------------------------------+ +val +auto(TT) const + +--------+-----------------------------------------+ +less +block<(a:TT const;b:TT const):bool> const+ +--------+-----------------------------------------+ 返回一个迭代器,该迭代器指向范围 [first, last] 中的第一个元素,该元素不小于(即大于或等于)值,如果未找到此类元素,则返回 last。 .. _function-_at_algorithm_c__c_binary_search_C._C._%_ls_IsAnyArrayMacro_c_expect_any_array(a_eq_true)_gr_: .. das:function:: binary_search(a: auto const; val: auto const) binary_search returns auto +--------+-------------+ +argument+argument type+ +========+=============+ +a +auto const + +--------+-------------+ +val +auto const + +--------+-------------+ now for all the other types .. _function-_at_algorithm_c__c_binary_search_C._Ci_Ci_C._%_ls_IsAnyArrayMacro_c_expect_any_array(a_eq_true)_gr_: .. das:function:: binary_search(a: auto const; f: int const; last: int const; val: auto const) binary_search returns auto +--------+-------------+ +argument+argument type+ +========+=============+ +a +auto const + +--------+-------------+ +f +int const + +--------+-------------+ +last +int const + +--------+-------------+ +val +auto const + +--------+-------------+ 现在适用于所有其他类型的 .. _function-_at_algorithm_c__c_binary_search_C._CY_ls_TT_gr_._CN_ls_a;b_gr_0_ls_CY_ls_TT_gr_L;CY_ls_TT_gr_L_gr_1_ls_b_gr__builtin__%_ls_IsAnyArrayMacro_c_expect_any_array(a_eq_true)_gr_: .. das:function:: binary_search(a: auto const; val: auto(TT) const; less: block<(a:TT const;b:TT const):bool> const) binary_search returns auto +--------+-----------------------------------------+ +argument+argument type + +========+=========================================+ +a +auto const + +--------+-----------------------------------------+ +val +auto(TT) const + +--------+-----------------------------------------+ +less +block<(a:TT const;b:TT const):bool> const+ +--------+-----------------------------------------+ 现在适用于所有其他类型的 .. _function-_at_algorithm_c__c_binary_search_C._Ci_Ci_CY_ls_TT_gr_._CN_ls_a;b_gr_0_ls_CY_ls_TT_gr_L;CY_ls_TT_gr_L_gr_1_ls_b_gr__builtin__%_ls_IsAnyArrayMacro_c_expect_any_array(a_eq_true)_gr_: .. das:function:: binary_search(a: auto const; f: int const; last: int const; val: auto(TT) const; less: block<(a:TT const;b:TT const):bool> const) binary_search returns auto +--------+-----------------------------------------+ +argument+argument type + +========+=========================================+ +a +auto const + +--------+-----------------------------------------+ +f +int const + +--------+-----------------------------------------+ +last +int const + +--------+-----------------------------------------+ +val +auto(TT) const + +--------+-----------------------------------------+ +less +block<(a:TT const;b:TT const):bool> const+ +--------+-----------------------------------------+ 现在适用于所有其他类型的 ++++++++++++++++++ Array manipulation ++++++++++++++++++ * :ref:`unique (a:array\ -const) : auto ` * :ref:`sort_unique (a:array\ -const) : auto ` * :ref:`reverse (a:array\ -const) : auto ` * :ref:`combine (a:array\ const;b:array\ const) : auto ` * :ref:`reverse (a:auto -const) : auto ` * :ref:`combine (a:auto const;b:auto const) : auto ` .. _function-_at_algorithm_c__c_unique_1_ls_Y_ls_TT_gr_._gr_A: .. das:function:: unique(a: array) unique returns auto +--------+---------------+ +argument+argument type + +========+===============+ +a +array+ +--------+---------------+ 返回已删除重复项的 a 的元素数组。 .. _function-_at_algorithm_c__c_sort_unique_1_ls_Y_ls_TT_gr_._gr_A: .. das:function:: sort_unique(a: array) sort_unique returns auto +--------+---------------+ +argument+argument type + +========+===============+ +a +array+ +--------+---------------+ 返回 的元素数组 a,已排序并删除了重复项。 a 的元素按升序排序。 生成的数组仅包含 unqiue 元素。 .. _function-_at_algorithm_c__c_reverse_1_ls_._gr_A: .. das:function:: reverse(a: array) reverse returns auto +--------+-------------+ +argument+argument type+ +========+=============+ +a +array + +--------+-------------+ 以相反的顺序返回 a 的元素数组。 .. _function-_at_algorithm_c__c_combine_C1_ls_Y_ls_TT_gr_._gr_A_C1_ls_Y_ls_TT_gr_._gr_A: .. das:function:: combine(a: array const; b: array const) combine returns auto +--------+---------------------+ +argument+argument type + +========+=====================+ +a +array const+ +--------+---------------------+ +b +array const+ +--------+---------------------+ 返回 a 和 b 的元素的数组。 .. _function-_at_algorithm_c__c_reverse_._%_ls_IsAnyArrayMacro_c_expect_any_array(a_eq_true)_gr_: .. das:function:: reverse(a: auto) reverse returns auto +--------+-------------+ +argument+argument type+ +========+=============+ +a +auto + +--------+-------------+ 以相反的顺序返回 a 的元素数组。 .. _function-_at_algorithm_c__c_combine_C._C._%_ls_IsAnyArrayMacro_c_expect_any_array(a_eq_true)_gr_: .. das:function:: combine(a: auto const; b: auto const) combine returns auto +--------+-------------+ +argument+argument type+ +========+=============+ +a +auto const + +--------+-------------+ +b +auto const + +--------+-------------+ 返回 a 和 b 的元素的数组。 +++++++++++++ Uncategorized +++++++++++++ .. _function-_at_algorithm_c__c_erase_all_._C._%_ls_IsAnyArrayMacro_c_expect_any_array(arr_eq_true)_gr_: .. das:function:: erase_all(arr: auto; value: auto const) erase_all returns auto +--------+-------------+ +argument+argument type+ +========+=============+ +arr +auto + +--------+-------------+ +value +auto const + +--------+-------------+ 从 arr 中擦除所有等于 value 的元素 .. _function-_at_algorithm_c__c_topological_sort_C1_ls_Y_ls_Node_gr_._gr_A: .. das:function:: topological_sort(nodes: array const) topological_sort returns auto +--------+-----------------------+ +argument+argument type + +========+=======================+ +nodes +array const+ +--------+-----------------------+ 拓扑结构是一种图。 每个节点都有一个 id 和 set(没有值的表)依赖项。 依赖项 `before` 表示来自节点的链接,该链接应出现在排序列表中的节点之前。 返回节点的排序列表。 .. _function-_at_algorithm_c__c_intersection_C1_ls_Y_ls_TT_gr_._gr_2_ls_v_gr_T_C1_ls_Y_ls_TT_gr_._gr_2_ls_v_gr_T: .. das:function:: intersection(a: table const; b: table const) intersection returns table +--------+--------------------------+ +argument+argument type + +========+==========================+ +a +table const+ +--------+--------------------------+ +b +table const+ +--------+--------------------------+ 返回两个集的交集 .. _function-_at_algorithm_c__c_union_C1_ls_Y_ls_TT_gr_._gr_2_ls_v_gr_T_C1_ls_Y_ls_TT_gr_._gr_2_ls_v_gr_T: .. das:function:: union(a: table const; b: table const) union returns table +--------+--------------------------+ +argument+argument type + +========+==========================+ +a +table const+ +--------+--------------------------+ +b +table const+ +--------+--------------------------+ 返回两个集合的并集 .. _function-_at_algorithm_c__c_difference_C1_ls_Y_ls_TT_gr_._gr_2_ls_v_gr_T_C1_ls_Y_ls_TT_gr_._gr_2_ls_v_gr_T: .. das:function:: difference(a: table const; b: table const) difference returns table +--------+--------------------------+ +argument+argument type + +========+==========================+ +a +table const+ +--------+--------------------------+ +b +table const+ +--------+--------------------------+ 返回两组的差值 .. _function-_at_algorithm_c__c_identical_C1_ls_Y_ls_TT_gr_._gr_2_ls_v_gr_T_C1_ls_Y_ls_TT_gr_._gr_2_ls_v_gr_T: .. das:function:: identical(a: table const; b: table const) identical returns bool +--------+--------------------------+ +argument+argument type + +========+==========================+ +a +table const+ +--------+--------------------------+ +b +table const+ +--------+--------------------------+ 如果两个集相同,则返回 true