pattern-matching

Haskell GHC: what is the time complexity of a pattern match with N constructors?

我的梦境 提交于 2019-12-28 03:46:28
问题 Let's say we have the following Haskell: data T = T0 | T1 | T2 | ... | TN toInt :: T -> Int toInt t = case t of T0 -> 0 T1 -> 1 T2 -> 2 ... TN -> N What algorithm is used to perform the pattern match here? I see two options: (1) Linear search, something like if (t.tag == T0) { ... } else if (t.tag == T1) { ... } else ... (2) Binary search, which would be sensible in this specific task: searching for t.tag in the set { TO ... T1023 }. However, where pattern matching in general has many other

Regex in xml not working as expected

本小妞迷上赌 提交于 2019-12-25 16:48:55
问题 I am novice here and I am trying to search and replace a string in a xml file which is as given below: <name>xxx.yyy_zzz</name> <constructor_arguments /> <parameters> <parameter> <name>Name</name> <string> <value>yyy</value> </string> </parameter> <parameter> <name>abc</name> <bool> <value>false</value> </bool> </parameter> <parameter> <name>abcd</name> <bool> <value>true</value> </bool> </parameter> <parameter> <name>aa</name> <integer> <value>10</value> </integer> </parameter> <parameter>

Regex in xml not working as expected

时光总嘲笑我的痴心妄想 提交于 2019-12-25 16:48:09
问题 I am novice here and I am trying to search and replace a string in a xml file which is as given below: <name>xxx.yyy_zzz</name> <constructor_arguments /> <parameters> <parameter> <name>Name</name> <string> <value>yyy</value> </string> </parameter> <parameter> <name>abc</name> <bool> <value>false</value> </bool> </parameter> <parameter> <name>abcd</name> <bool> <value>true</value> </bool> </parameter> <parameter> <name>aa</name> <integer> <value>10</value> </integer> </parameter> <parameter>

Linux script: how to split a text into different files with match pattern

谁说胖子不能爱 提交于 2019-12-25 10:55:34
问题 For example: I have a text as following: Jul 11 xxxx xxxx start xxxxx .... .... .... Jul 11 xxxx xxxx stop xxxxx Jul 11 xxxx xxxx start xxxxx .... .... .... Jul 11 xxxx xxxx stop xxxxx .... now I want to split the above text file into different files based on "start" and "stop", like /***text1.txt******/ Jul 11 xxxx xxxx start xxxxx .... .... .... Jul 11 xxxx xxxx stop xxxxx /***text2.txt******/ Jul 11 xxxx xxxx start xxxxx .... .... .... Jul 11 xxxx xxxx stop xxxxx How can I do that? Thanks.

web2py rest api endpoint gives invalid path output

烂漫一生 提交于 2019-12-25 07:09:23
问题 I have made a web2py web application. The api endpoints exposed are as follows. "/comments[comments]" "/comments/id/{comments.id}" "/comments/id/{comments.id}/:field" "/comments/user-id/{comments.user_id}" "/comments/user-id/{comments.user_id}/:field" "/comments/date-commented/{comments.date_commented.year}" "/comments/date-commented/{comments.date_commented.year}/:field" "/comments/date-commented/{comments.date_commented.year}/{comments.date_commented.month}" "/comments/date-commented/

SQL new column with pattern match

╄→гoц情女王★ 提交于 2019-12-25 06:52:04
问题 I have a column with a url sting that looks like this http://www.somedomain.edu/rootsite1/something/something/ or http://www.somedomain.edu/sites/rootsite2/something/something Basically I want to ONLY return the string up to root site (in another column).. root site can be anyting (but /sites), but it will either follow /sites/ or .edu/ so the above two strings would return: http://www.somedomain.edu/rootsite1 http://www.somedomain.edu/sites/rootsite2 I can't compile the view with CLR, so I

How to display text after pattern in vbscript?

末鹿安然 提交于 2019-12-25 04:25:25
问题 I have a file with the following text as a result of my other vbscript: "Name": "stopped" "LaunchTime": "2015-02-13<some-text>", "InstanceId": "i-<something>", "Name": "stopped" "LaunchTime": "2015-02-13T17:24:11.000Z", "InstanceId": "i-<something>", "Name": "stopped" "LaunchTime": "2015-02-12<some-text>", "InstanceId": "i-<something>", I want to use 4 characters as delimiter -> ": " (which is 4 characters) and display everything at the right side of it, so the result will look like this:

Algorithm Efficiency Pattern Matching, Checking for image inside image

断了今生、忘了曾经 提交于 2019-12-25 03:57:15
问题 This is a more descriptive version of my previous question. The problem I am trying to solve relates to block-matching or image-within-image recognition. I see an image, extract the [x,y] of every black pixel and create a set for that image, such as {[8,0], [9,0], [11,0]} The set is then augmented so that the first pixel in the set is at [0,0], but the relationship of the pixels is preserved. For example, I see {[8,0], [9,0]} and change the set to {[0,0], [1,0]}. The point of the extraction

Recognizing the Swiping pattern for screen lock n unlock ios

二次信任 提交于 2019-12-25 02:47:13
问题 I want to create a swiping pattern for lock and unlock the screen(swiping without taking off the finger). How can I do that with UISwipeGestureRecognizer. I want to save it and match it when I again try to login. How can I save that? As an image or something else?. Please do help me with this. Thank you. 回答1: Android Pattern Lock on iPhone for iOS A Pattern Lock for iOS similar to the one in Android 回答2: What do you mean when you talk about "pattern", and what exactly do you want to save? You

Recognizing the Swiping pattern for screen lock n unlock ios

▼魔方 西西 提交于 2019-12-25 02:47:01
问题 I want to create a swiping pattern for lock and unlock the screen(swiping without taking off the finger). How can I do that with UISwipeGestureRecognizer. I want to save it and match it when I again try to login. How can I save that? As an image or something else?. Please do help me with this. Thank you. 回答1: Android Pattern Lock on iPhone for iOS A Pattern Lock for iOS similar to the one in Android 回答2: What do you mean when you talk about "pattern", and what exactly do you want to save? You