O(mn)和O(mnlgn)(O(mn) and O(mnlgn))
对于上面的两个大O,如果n >> m会发生什么。 大O如何改变? 它在第一种情况下变成了O(n)吗? 如果是,为什么?
for the above 2 big O's, what happens if n>>m . How does the big O change? Does it become O(n) in the first case. If yes ,why?
原文:https://stackoverflow.com/questions/5290598
最满意答案
罗杰
这是一个有效的,经过测试的用例语法。 我尝试使用你所拥有的但它失败并且看起来不完整。 以下是两个示例,用于演示条件存在时的可选外观:
S = A <space> B [<space> optC] A = "a" B = "b" C = "c" optC = C space = #' '
以下是两个输出:
;input 1 = "a b" ;produces => [:S [:A "a"] [:B "b"]] input 2 = "a b c" ;produces => [:S [:A "a"] [:B "b"] [:optC [:C "c"]]]
用你的语法。 正如我所说,我遇到了麻烦,因为它似乎没有完全定义,但一般来说:
(* If you change this *) interface = <interface_dec> uses (* to this, you should get similar results *) interface = <interface_dec> [uses]
如果这不起作用,那么您需要提供一个语法,该语法与提供的输入样本一起使用,因为它们似乎不同步。
Roger
Here is a valid, tested use case grammar. I tried using what you have but it is failing and doesn't appear complete. Following this are two examples to demonstrate optional appearance if condition exists:
S = A <space> B [<space> optC] A = "a" B = "b" C = "c" optC = C space = #' '
Here are the two outputs:
;input 1 = "a b" ;produces => [:S [:A "a"] [:B "b"]] input 2 = "a b c" ;produces => [:S [:A "a"] [:B "b"] [:optC [:C "c"]]]
With your grammar. As I said, I was having trouble as it does not appear fully defined but generally speaking:
(* If you change this *) interface = <interface_dec> uses (* to this, you should get similar results *) interface = <interface_dec> [uses]
If that doesn't work then you would need to provide a grammar that works with the input sample provided as they seem out of synch.
相关问答
更多-
我会创建两个SimpleDateFormat,一个带有时区,另一个没有。 您可以查看字符串的长度以确定要使用哪一个。 听起来你需要一个DateFormat,它代表两个不同的SDF。 DateFormat df = new DateFormat() { static final String FORMAT1 = "yyyyMMddHHmmss"; static final String FORMAT2 = "yyyyMMddHHmmssz"; final SimpleDateForma ...
-
如何将instaparse输出转换为可以评估的函数?(How to transform instaparse output into a function that can be evaluated?)[2021-01-13]
您可以为查询语言编写一个小编译器,使用instaparse生成一个解析树,使用常规Clojure函数将其转换为Clojure代码,最后生成一个Clojure函数,然后将其应用于您的记录。 对eval的初始调用会有些昂贵,但结果函数将等同于在源文件中手动编写的函数,并且不会带来性能损失。 实际上,这是eval一个罕见的有效用例 - 生成一个函数,其代码以真正动态的方式构造,然后将被调用很多次。 显然,当遵循这种方法时,您需要确保您不会无意中允许不受信任的源执行任意代码。 为了演示,这里是一个基于非常简单的语法 ... -
罗杰 这是一个有效的,经过测试的用例语法。 我尝试使用你所拥有的但它失败并且看起来不完整。 以下是两个示例,用于演示条件存在时的可选外观: S = A
B [ optC] A = "a" B = "b" C = "c" optC = C space = #' ' 以下是两个输出: ;input 1 = "a b" ;produces => [:S [:A "a"] [:B "b"]] input 2 = "a b c" ;produces => [:S [:A ... -
React路由器使用path-to-regexp - https://github.com/pillarjs/path-to-regexp 您可以将可选的非参数与这样的路径匹配: const path = "/to/page/:pathParam1?/(otherParam)?/:pathParam2?" 并测试它: const re = pathToRegexp(path) console.log(re.exec("/to/page/1")) // ["/to/page/1", "1", undefi ...
-
这是一个工作示例项目: project.clj: (defproject parse "0.1.0-SNAPSHOT" :description "FIXME: write description" :url "http://example.com/FIXME" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies ...
-
当您在输入上使用parser本身而不是通过insta/parses ,它会在REPL处输出错误的错误消息。 一个例子: (def ebnf "expr = A DOT A = 'A' DOT = '.'") user> ((insta/parser ebnf) "A.") [:expr [:A "A"] [:DOT "."]] user> ((insta/parser ebnf) "B.") Parse error at line 1, column 1: B. ^ Expecte ...
-
您可以传递可选参数以启用自动空白: (doc insta/parser) ------------------------- instaparse.core/parser ([grammar-specification & {:as options}]) :auto-whitespace (:standard or :comma) or :auto-whitespace custom-whitespace-parser You can pass an optional parameter ...
-
你只要把它们当作字符串来处理。 例如: ((insta/parser "S = '<' tag '>' tag = #'\\w+' ") "") ; [:S "<" [:tag "html"] ">"] 在instaparse中,您可以使用尖括号<>隐藏已解析的元素,从树输出中抑制它们。 ((insta/parser "S = <'<'> tag <'>'> tag = #'\\w+' ") "") ; [:S [:tag "html"]] ...
-
Python RegEx - 如何处理字符串中的可选部分(Python RegEx - How can I handle optional parts in a string)[2021-11-05]
你只需要添加? 两个非捕获组的(零或一个匹配)量词。 -[A-Z1-9]{2,8}(?: \(Alarm .*?\))?(?: \(Box .*\))? (.*?)\. \( 现在它应该工作,无论是否存在Alarm Type和Box 。 DEMO You just need to add ? (zero or one match) quantifiers to both non-capturing groups. -[A-Z1-9]{2,8}(?: \(Alarm .*?\))?(?: \(Box .*\ ... -
我真的不知道instaparser,所以我只是阅读了足够的文档来给我一种虚假的安全感。 我也没有测试,我真的不知道你的要求是什么。 特别是,我不知道: 1)$()是否可以嵌套(我认为你的语法不可能,但我觉得这很奇怪) 2)是否()可以包含空格而不被解析为多个单词 3)是否()可以包含$() 你需要清楚这样的事情才能写出语法(或者,当它发生时,要求建议)。 更新 : 根据评论修改语法。 我删除了$ (和)因为它们似乎没必要,这样角括号感觉更容易处理。 以下是基于回答上述问题“是,否,是”以及关于正则表达式格式 ...