标签: clone

如何加速我的自定义结构中的 Rust 克隆方法?

我在 Rust 中有结构体,其中包含以下字段及其类型:

\n
    \n
  • 五个i8
  • \n
  • 六架F32
  • \n
  • 一布尔
  • \n
  • 一个大小为 4 的 Vec
  • \n
  • 一个大小为 4x20x7 的 Vec<Vec<Vec>>
  • \n
  • 一个大小为 4x20 的 Vec<Vec>
  • \n
  • 一个 HashMap<i8, Vec> 有 4 个键
  • \n
  • 一个大小从 0 到 30 变化的 Vec<(i8, i8)>
  • \n
\n

我的问题是如何加速这种结构的对象的克隆?\n现在我只使用

\n
fn py_make_copy(&self) -> PyResult<Self> {\n    Ok(self.clone())\n}\n
Run Code Online (Sandbox Code Playgroud)\n

它需要 4 到 6 \xc2\xb5s,这对我来说太慢了。我正在用 Python 测量它。\n不幸的是,我必须深度复制这些对象。

\n

我不知道这是否相关,但我使用

\n
#[pyclass(subclass)]\n#[derive(Clone)]\n
Run Code Online (Sandbox Code Playgroud)\n

定义此 Struct 和 #[pyo3(get)] 到所有字段时。

\n

我尝试使用 par_iter 并行克隆,但它的持续时间比 py_make_copy 长得多。

\n

python struct clone rust pyo3

0
推荐指数
1
解决办法
208
查看次数

如何从jQuery选择或克隆的html中删除元素?

我正在构建一个jQuery mini-plugin来显示打印预览,然后打印我的应用程序运行的一些报告的结果.我需要能够不打印某些部分(例如:没有结果的报告,UI元素等).我试过css @media print无济于事.我不知道为什么它不起作用,但我完全按照w3schools媒体类型页面上的描述实现它,IE仍然想要打印这些元素.

所以我决定暴力破解它,只是从克隆的DOM中删除.noPrint元素.事实证明,这将解决我期待的计划"输出到.pdf"功能的问题.

我的问题是,虽然

    $(clonedHtml).find('.noPrint') 
Run Code Online (Sandbox Code Playgroud)

很好地返回noPrint元素的集合,

    $(clonedHtml).remove('.noPrint') 
Run Code Online (Sandbox Code Playgroud)

不删除任何东西.我也尝试过这样删除它:

    var removeMe = $(clonedHtml).find('.noPrint');
    clonedHtml.remove(removeMe);
Run Code Online (Sandbox Code Playgroud)

这显然也无效.此语法基于API文档的第二个示例:

    $("p").remove(":contains('Hello')");
    Removes all paragraphs that contain "Hello" from the DOM. Analogous to doing 
    $("p").filter(":contains('Hello')").remove(). 
Run Code Online (Sandbox Code Playgroud)

真正的问题:为什么?我检查了删除()的API文档,我已经阅读了我在谷歌上找到的所有内容,并且我搜索了jQuery论坛但找不到任何内容.

css jquery clone find

-1
推荐指数
1
解决办法
2726
查看次数

覆盖克隆方法 - 不工作(Java)

我正在编写一个搜索算法来解决java中的15个难题.当我克隆谜题状态以产生新的可能动作(女儿)时,它们仍然相互改变而不是分开.

这是我的克隆方法:

public FifteenPuzzleState clone() throws CloneNotSupportedException
{
FifteenPuzzleState copy = (FifteenPuzzleState)super.clone();
for(int i=0; i<copy.currentConfig.length; i++){
    copy.currentConfig[i] = Arrays.copyOf(currentConfig[i], currentConfig[i].length);
}
return copy;     
} 
Run Code Online (Sandbox Code Playgroud)

所以我的问题是,在克隆状态然后改变它之后,它也会影响先前的状态和所有其他克隆.我的第一个想法是我没有正确创建2d数组的深层副本,但我发现上面的代码没有任何问题.

有什么建议?谢谢

java clone deep-copy

-1
推荐指数
1
解决办法
201
查看次数

c ++中克隆系统调用句子中的错误

我试图在c ++中运行c代码,里面使用了clone,我得到了一个我无法解决的错误,任何人之前在c ++中使用了clone,并且可以提供帮助.

我的代码:

int variable, fd;
using namespace std ;
int do_something() {
variable = 42;cout << "sana" << endl ;
close(fd);
_exit(0);
}

int main() {
void **child_stack;
char tempch;

variable = 9;
fd = open("test.file", O_RDONLY);
child_stack = (void **) malloc(16384);
printf("The variable was %d\n", variable);

clone(do_something, child_stack,CLONE_VM|CLONE_FILES, NULL);
sleep(1);

printf("The variable is now %d\n", variable);
if (read(fd, &tempch, 1) < 1) {
  perror("File Read Error");
  exit(1);
}
printf("We could read from the file\n");
return 0;
} …
Run Code Online (Sandbox Code Playgroud)

c++ linux clone

-1
推荐指数
1
解决办法
447
查看次数

(this).parent().find('.classname')不起作用

我正在尝试点击事件,用户点击Div问题,然后Jquery克隆Div答案并将其显示在单独的Div Clone中.

示例:http: //jsfiddle.net/jessikwa/zNL63/2/

由于某种原因,以下变量返回null.有任何想法吗?

 var answer = $(this).parent().find(".faq-answer").clone();
Run Code Online (Sandbox Code Playgroud)

完整代码:

$(document).ready(function () {
    var faqQuestion = $('.faq-question');
    var faqClone = $('.faq-clone');

    faqQuestion.click(function () {
        showAnswer();
    });

    faqClone.click(function () {
        hideAnswer();
    });

    function showAnswer() {
        $(".faq-clone").hide("slide");
        $('.faq-clone').html("");

        var answer = $(this).parent().find(".faq-answer").clone();
        $('.faq-clone').append(answer.html());
        $(".faq-clone").show("slide");
    }

    function hideAnswer() {
        $(".faq-clone").hide("slide");
        $('.faq-clone').html("");
    }
});
Run Code Online (Sandbox Code Playgroud)

html javascript css jquery clone

-1
推荐指数
1
解决办法
1788
查看次数

克隆在桌面和zip下载之间的区别

下载克隆项目有什么区别?我克隆了一个项目,它成了一个存储库.我桌面上自己的项目是否成为社区的新项目?

而且,当Android工作室告诉我时它意味着什么:

未注册的VCS根目录.该目录在Git下,但它是在设置中注册的注释.

请不要回答我说我的项目中有一个Git项目,我知道.我只是想知道它是什么意思?

git clone android-studio

-1
推荐指数
1
解决办法
3284
查看次数

java:深度复制列表列表的最佳方法

我正在尝试编写一个程序来执行 的深拷贝List<List<Integer>>,我正在这样做:

public static List<List<Integer>> clone(final List<List<Integer>> src)
{
    List<List<Integer>> dest = new ArrayList<List<Integer>>();
    for( List<Integer> sublist : src) {
        List<Integer> temp = new ArrayList<Integer>();
        for(Integer val: sublist) {
            temp.add(val);
        }
        dest.add(temp);
    }
    return dest ;
} 
Run Code Online (Sandbox Code Playgroud)

这是一个好方法吗?是否有可能摆脱内循环?事实上,每个内部子列表都可以增长到很大的长度。

java clone list arraylist deep-copy

-1
推荐指数
1
解决办法
4096
查看次数

如何克隆一堆整数?

这个看似极其简单的问题困扰了我好几个小时.我正在尝试克隆一堆整数对象.我试过了

Stack<Integer> newStack = (Stack<Integer>)oldStack.clone();
Run Code Online (Sandbox Code Playgroud)

然而,这给我一个错误说 clone() has protected access in java.lang.Object

我最好的猜测是因为Integer没有实现clone(),所以我收到了这个错误.那么我应该如何克隆一堆整数呢?

java stack integer clone

-2
推荐指数
1
解决办法
4025
查看次数

带有html()的jquery clone()不是函数

创建我自己的照片库我想加载小图片到更大的div来扩大它.首先,我使用html(),但它删除主(小)照片,或什么都不做(我发现几个解决方案如何使用html()而不是降低主要数据,但没有tchem工作).所以我尝试使用clone().但后来我尝试将它与html()结合起来,它给我一个错误:this.clone不是一个函数.我再次尝试找到解决方案,但没有任何效果.这是我尝试使用的解决方案和效果的代码:

<script>
var GallObj={
    img:<?php echo json_encode($GetImg->jsonData); ?>,
    imgIndex:new Number, //storage data about index of enlaging picture
}

var showAllImg = $.map(GallObj.img, function(val, i) {
    return "<img src='gallery/"+val+"' class='smallimg'>";
});

$("#gallCont").html(showAllImg.join(""));

$('.smallimg').click(function(){
    GallObj.imgIndex=$('.smallimg').index(this);

   //it work, but I need change it and use html() because it doesn't change one loaded photo to new loaded photo of course:
   $(this).clone().appendTo($('#picture')); 

   // this two removed clicked oryginalny picture and I don't want it:
   $('#picture').html(this)
   $('#picture').html(this).html(); 

   //this.clone is not a function error:
   elm=this.clone();
   $('#picture').html(elm);

   //this.clone …
Run Code Online (Sandbox Code Playgroud)

html jquery clone

-2
推荐指数
1
解决办法
2794
查看次数

标签 统计

clone ×9

java ×3

jquery ×3

css ×2

deep-copy ×2

html ×2

android-studio ×1

arraylist ×1

c++ ×1

find ×1

git ×1

integer ×1

javascript ×1

linux ×1

list ×1

pyo3 ×1

python ×1

rust ×1

stack ×1

struct ×1