标签: sequence

如何创建PostgreSQL分区序列?

是否有一种简单的(即非hacky)和无竞争条件的方法来在PostgreSQL中创建分区序列.例:

在问题中使用正常序列:

| Project_ID | Issue |
| 1          | 1     |
| 1          | 2     |
| 2          | 3     |
| 2          | 4     |
Run Code Online (Sandbox Code Playgroud)

在问题中使用分区序列:

| Project_ID | Issue |
| 1          | 1     |
| 1          | 2     |
| 2          | 1     |
| 2          | 2     |
Run Code Online (Sandbox Code Playgroud)

postgresql partitioning sequence

5
推荐指数
1
解决办法
2400
查看次数

检查R中的向量是否是连续的?

如何检查整数向量是否是"顺序"的,即后续元素之间的差异恰好是1.我觉得我错过了像"is.sequential"这样的东西

这是我自己的功能:

is.sequential <- function(x){
    all(diff(x) == rep(1,length(x)-1))
}    
Run Code Online (Sandbox Code Playgroud)

r sequence

5
推荐指数
1
解决办法
1592
查看次数

在每个索引处生成具有唯一值的多个数字序列

我有一排数字1:n.我正在寻找第二行也有数字,1:n但这些应该是随机顺序,同时满足以下要求:

  1. 两个行中没有位置具有相同的数字
  2. 没有数字组合出现两次

例如,在下面

Row 1:  1  2  3  4  5  6  7 ...
Row 2:  3  6  15 8  13 12 7 ...  
Run Code Online (Sandbox Code Playgroud)

数字7出现在第1行和第2行的相同位置(即位置7;因此不满足规则1)

而在下面

Row 1:  1  2  3  4  5  6  7 ...
Row 2:  3  7  15 8  13 12 2 ...
Run Code Online (Sandbox Code Playgroud)

2 + 7的组合出现两次(在第2和第7位;因此不满足规则2).

或许可以 - 但是不必要地耗费时间 - 手工完成(至少直到合理的数量),但在MATLAB中必须有相当优雅的解决方案.

random algorithm matlab sequence combinatorics

5
推荐指数
1
解决办法
562
查看次数

如何在CORBA中获取和设置类字段?(处理CORBA对象的序列)

我有这样的事:

User.idl:

#ifndef __USER_IDL__
#define __USER_IDL__

interface Group;

interface User
{
    typedef sequence<Group> Groups;
    Groups getGroups();
    void setGroups(in Groups g);
};

#endif
Run Code Online (Sandbox Code Playgroud)

UserImpl.h和UserImpl.cpp:

class UserImpl : public POA_User
{
    private :
        User::Groups groups;
    public :

        User::Groups* getGroups();
        void setGroups(const ::User::Groups& g);
};

#endif

#include "UserImpl.h"

User::Groups* UserImpl::getGroups()
{
    return &(this->groups);
}

void UserImpl::setGroups(const ::User::Groups& g)
{
    this->groups.length(g.length());
    for(int i=0; i<g.length(); i++)
    {
        this->groups[i] = this->groups[i];
    }
}
Run Code Online (Sandbox Code Playgroud)

和Group.idl:

#ifndef __GROUP_IDL__
#define __GROUP_IDL__

#include "User.idl"

interface Group
{
    typedef sequence<User> Users; …
Run Code Online (Sandbox Code Playgroud)

c++ corba sequence omniorb

5
推荐指数
1
解决办法
423
查看次数

在F#中旋转或压缩seq <seq <'a >>

假设我有一系列序列,例如

{1, 2, 3}, {1, 2, 3}, {1, 2, 3}
Run Code Online (Sandbox Code Playgroud)

什么是旋转或拉链这个序列的最佳方法,所以我反而拥有,

{1, 1, 1}, {2, 2, 2}, {3, 3, 3}
Run Code Online (Sandbox Code Playgroud)

有没有一种可理解的方式这样做而不诉诸操纵底层IEnumerator<_>类型?

澄清一下,这些是seq<seq<int>>对象.每个序列(内部和外部)可以包含任意数量的项目.

f# pivot functional-programming sequence

5
推荐指数
1
解决办法
870
查看次数

保存到数据库之前获取ID

我使用hibernate序列来生成实体的id.我使用PostgreSQL 9.1.

是否可以在将实体ID保存到数据库之前获取它?怎么样?

java postgresql hibernate sequence

5
推荐指数
1
解决办法
7172
查看次数

Swift SequenceType不起作用

我正在尝试实现SequenceType/GeneratorType示例并获得一个不太有意义的错误.

这是代码:

// Here's my GeneratorType - it creates a random-number Generator:
struct RandomNumberGenerator:GeneratorType {
    typealias Element = Int
    mutating func next() -> Element? {
       return Int(arc4random_uniform(100))
    }
} 
Run Code Online (Sandbox Code Playgroud)

当我打电话给它(在Playgrounds中)时,它的效果非常好:

var randyNum = RandomNumberGenerator()
randyNum.next()   // this shows a valid random number in the Gutter
// And calling it from within a println also works:
println("randyNum = \(randyNum.next()!)")
Run Code Online (Sandbox Code Playgroud)

到目前为止一切都那么好.

接下来是SequenceType:

struct RandomNumbersSequence:SequenceType {
    typealias Generator = RandomNumberGenerator
    var numberOfRandomNumbers:Int

    init(maxNum:Int) {
        numberOfRandomNumbers = maxNum
    }

    func generate() -> Generator { …
Run Code Online (Sandbox Code Playgroud)

foreach generator sequence for-in-loop swift

5
推荐指数
1
解决办法
1351
查看次数

在Oracle中插入带序列的多行

这是我用于在oracle数据库中插入多行的查询.但是当我在其中使用序列时,它会引发错误,如ORA-00001:唯一约束.怎么做.

INSERT ALL
  INTO POSTAL_CODE( postal_code,desc)
    VALUES(postal_code.NEXTVAL,'Coimbatore')
  INTO POSTAL_CODE (postal_code,desc)
    VALUES(postal_code.NEXTVAL,'Mumbai') SELECT * FROM DUAL;
Run Code Online (Sandbox Code Playgroud)

oracle sequence multiple-insert

5
推荐指数
2
解决办法
9504
查看次数

符合Swift中的Sequence和IteratorProtocol

我正在尝试编写自己的版本,IndexingIterator以加深我对的了解Sequence。我尚未在结构中将任何类型分配给关联类型迭代器。但是,编译器对此并没有抱怨,我得到了的默认实现makeIterator。

以下是我的代码:

struct __IndexingIterator<Elements: IndexableBase>: Sequence, IteratorProtocol {
    mutating func next() -> Elements._Element? {
        return nil
    }
}
let iterator = __IndexingIterator<[String]>()
// this works and returns an instance of __IndexingIterator<Array<String>>. why?
iterator.makeIterator() 
Run Code Online (Sandbox Code Playgroud)

我认为必须有一些扩展Sequence可以添加默认实现。因此,我搜索了它Sequence.swift,才发现了它。

extension Sequence where Self.Iterator == Self, Self : IteratorProtocol {
  /// Returns an iterator over the elements of this sequence.
  public func makeIterator() -> Self {
    return self
  }
}
Run Code Online (Sandbox Code Playgroud)

我以为会是这样的:

extension Sequence where Self: IteratorProtocol …
Run Code Online (Sandbox Code Playgroud)

sequence swift swift-protocols swift3

5
推荐指数
1
解决办法
1641
查看次数

获取值的运行的开始和结束索引

我有一个矢量:

a <- c(1, 1, 0, 0, 1, 2, 0, 0)
Run Code Online (Sandbox Code Playgroud)

我想得到每次运行相等值的开始和结束索引:

number start  end
0        3     4
0        7     8
1        1     2
1        5     5
2        6     6
Run Code Online (Sandbox Code Playgroud)

r sequence

5
推荐指数
1
解决办法
353
查看次数