sequences

How to delete unused sequences?

≡放荡痞女 提交于 2019-11-29 14:54:16
问题 We are using PostgreSQL. My requirement is to delete unused sequences from my database. For example, if I create any table through my application, one sequence will be created, but for deleting the table we are not deleting the sequence, too. If want to create the same table another sequence is being created. Example: table: file ; automatically created sequence for id coumn: file_id_seq When I delete the table file and create it with same name again, a new sequence is being created (i.e.

Best practice for shifting a sequence in a circular manner

北城余情 提交于 2019-11-28 21:21:34
I have to implement a kind of an array or sequence or list, which supports the cheapest way of circulated forwarding and back winding of elements. See this example: Original sequence: 1 2 3 4 5 Forwarded once: 5 1 2 3 4 Forwarded twice: 4 5 1 2 3 Same but opposite is for the back winding. What would be the cheapest and most Scala-style way of implementing this? In Java I could use LinkedList and it would do great... However, I could not find any definite answer for Scala. Also, it also has to be easy to replace any given element by index, as in LinkedList. UPDATE: For the fastest, but not-so

In Clojure, when should I use a vector over a list, and the other way around?

↘锁芯ラ 提交于 2019-11-28 15:18:48
I read that Vectors are not seqs, but Lists are. I'm not sure what the rationale is for using one over the other. It seems that vectors are used the most, but is there a reason for that? Once again, it seems I've answered my own question by getting impatient and asking it in #clojure on Freenode. Good thing answering your own questions is encouraged on Stackoverflow.com :D I had a quick discussion with Rich Hickey, and here is the gist of it. [12:21] <Raynes> Vectors aren't seqs, right? [12:21] <rhickey> Raynes: no, but they are sequential [12:21] <rhickey> ,(sequential? [1 2 3]) [12:21]

Avoiding stack overflow (with F# infinite sequences of sequences)

时光总嘲笑我的痴心妄想 提交于 2019-11-28 06:47:47
I have this "learning code" I wrote for the morris seq in f# that suffers from stack overflow that I don't know how to avoid. "morris" returns an infinite sequence of "see and say" sequences (i.e., {{1}, {1,1}, {2,1}, {1,2,1,1}, {1,1,1,2,2,1}, {3,1,2,2,1,1},...}). let printList l = Seq.iter (fun n -> printf "%i" n) l printfn "" let rec morris s = let next str = seq { let cnt = ref 1 // Stack overflow is below when enumerating for cur in [|0|] |> Seq.append str |> Seq.windowed 2 do if cur.[0] <> cur.[1] then yield!( [!cnt ; cur.[0]] ) cnt := 0 incr cnt } seq { yield s yield! morris (next s) //

How can I remove an item from a sequence in Clojure?

江枫思渺然 提交于 2019-11-28 05:45:48
First, I assume each structure-specific sequences would have different ways to remove an item: Vectors could be by index, List could be remove first or last, Set should be passing of the actual item to remove, etc. Second, I assume there are some methods for removal that are structure agnostic; they work on seq interface. Since sequences are immutable in Clojure, I suspect what you're actually doing is making a cheap copy of the original, only without the original item. This means list comprehension could be used for removal, but I suspect it would be unnecessarily verbose. Please give some

Detecting sequence of at least 3 sequential numbers from a given list

*爱你&永不变心* 提交于 2019-11-28 05:24:25
I have a list of numbers e.g. 21,4,7,9,12,22,17,8,2,20,23 I want to be able to pick out sequences of sequential numbers (minimum 3 items in length), so from the example above it would be 7,8,9 and 20,21,22,23. I have played around with a few ugly sprawling functions but I am wondering if there is a neat LINQ-ish way to do it. Any suggestions? UPDATE: Many thanks for all the responses, much appriciated. Im am currently having a play with them all to see which would best integrate into our project. Jon Skeet's / Timwi's solutions are the way to go. For fun, here's a LINQ query that does the job

Python: check if an object is a sequence

微笑、不失礼 提交于 2019-11-27 20:21:25
In python is there an easy way to tell if something is not a sequence? I tried to just do: if x is not sequence but python did not like that iter(x) will raise a TypeError if x cannot be iterated on -- but that check "accepts" sets and dictionaries, though it "rejects" other non-sequences such as None and numbers. On the other hands, strings (which most applications want to consider "single items" rather than sequences) are in fact sequences (so, any test, unless specialcased for strings, is going to confirm that they are). So, such simple checks are often not sufficient. In Python 2.6 and

Best practice for shifting a sequence in a circular manner

孤街浪徒 提交于 2019-11-27 13:44:24
问题 I have to implement a kind of an array or sequence or list, which supports the cheapest way of circulated forwarding and back winding of elements. See this example: Original sequence: 1 2 3 4 5 Forwarded once: 5 1 2 3 4 Forwarded twice: 4 5 1 2 3 Same but opposite is for the back winding. What would be the cheapest and most Scala-style way of implementing this? In Java I could use LinkedList and it would do great... However, I could not find any definite answer for Scala. Also, it also has to

In Clojure, when should I use a vector over a list, and the other way around?

佐手、 提交于 2019-11-27 09:10:05
问题 I read that Vectors are not seqs, but Lists are. I'm not sure what the rationale is for using one over the other. It seems that vectors are used the most, but is there a reason for that? 回答1: Once again, it seems I've answered my own question by getting impatient and asking it in #clojure on Freenode. Good thing answering your own questions is encouraged on Stackoverflow.com :D I had a quick discussion with Rich Hickey, and here is the gist of it. [12:21] <Raynes> Vectors aren't seqs, right?

I want to generate the nth term of the sequence 1,3,8,22,60 ,164 in Order(1) or order of (nlogn)

自作多情 提交于 2019-11-27 05:33:27
This sequence satisfies a(n+2) = 2 a(n+1) + 2 a(n). and also a(n)=[(1+sqrt(3))^(n+2)-(1-sqrt(3))^(n+2)]/(4sqrt(3)). I am using C++ for me n can vary from 1 to 10^ 9. I need the answers modulo (10^9)+7 But speed here is very important My code with formula1 is slow for numbers > 10^7 #include <iostream> #define big unsigned long long int #include<stdlib.h> int ans[100000001]={0}; big m =1000000007; using namespace std; int main() { //cout << "Hello world!" << endl; big t,n; cin>>t; big a,b,c; a=1; b=3; c=8; ans[0]=0; ans[1]=1; ans[2]=3; ans[3]=8; for(big i=3;i<=100000000;i++) { ans[i]=(((((ans[i