首页 \ 问答 \ 如何在STL中实现Stack?(How is Stack implemented in STL?)

如何在STL中实现Stack?(How is Stack implemented in STL?)

我遇到了这个:

标准C ++容器

它引发了我的问题,如何在STL中实现堆栈?

我正在寻找类似于的描述:

C ++ std :: vector是如何实现的?

什么是STL的双端队列?


I came across this:

Standard C++ Containers

It triggered me the question, how are stacks implemented in STL?

I am looking for a description similar to:

How is C++ std::vector implemented?

What really is a deque in STL?


原文:https://stackoverflow.com/questions/35930251
更新时间:2023-07-19 22:07

最满意答案

git merge --abort没有直接的等价物 - 在JGit中是不可用的。 这段代码可以作为一个起点:

// clear the merge state
repository.writeMergeCommitMsg( null );
repository.writeMergeHeads( null );

// reset the index and work directory to HEAD
Git.wrap( repository ).reset().setMode( ResetType.HARD ).call();

它清空合并状态文件,然后将索引和工作目录重置为当前HEAD提交的内容。

为了测试两个提交是否可以合并,您还可以使用内核合并 。 这将避免检查工作目录中的冲突提交,以便稍后重置它们。

RevCommit parentCommit = mergeCommit.getParent( 0 );
revWalk.parseHeaders( parentCommit );

ResolveMerger merger = ( ResolveMerger )MergeStrategy.RESOLVE.newMerger( repository, true );
merger.setWorkingTreeIterator( new FileTreeIterator( repository ) );
merger.setBase( parentCommit.getTree() );
if( !merger.merge( headCommit, mergeCommit ) ) {
  if( merger.failed() {
    throw new IllegalStateException( "Should not happen with in-core mergers" );
  }
  // inspect merger.getMergeResults() for further details
}

There is no direct equivalent for git merge --abort in JGit. This code snippet may serve as a starting point:

// clear the merge state
repository.writeMergeCommitMsg( null );
repository.writeMergeHeads( null );

// reset the index and work directory to HEAD
Git.wrap( repository ).reset().setMode( ResetType.HARD ).call();

It empties the merge state files and then resets index and work directory to the contents of the current HEAD commit.

In order to test if two commits can be merged, you could also use an in-core merger. This would avoid checking out the conflicting commit into the work directory just to reset them later on.

RevCommit parentCommit = mergeCommit.getParent( 0 );
revWalk.parseHeaders( parentCommit );

ResolveMerger merger = ( ResolveMerger )MergeStrategy.RESOLVE.newMerger( repository, true );
merger.setWorkingTreeIterator( new FileTreeIterator( repository ) );
merger.setBase( parentCommit.getTree() );
if( !merger.merge( headCommit, mergeCommit ) ) {
  if( merger.failed() {
    throw new IllegalStateException( "Should not happen with in-core mergers" );
  }
  // inspect merger.getMergeResults() for further details
}

相关问答

更多
  • user this commond check merged commit $ git log $(git merge-base --octopus $(git log -1 --merges --pretty=format:%P)).. --boundary
  • 使用GitSCM的checkout步骤,它具有扩展名以指定要使用的Git工具。 为方便起见, git步骤只有少数最常见的选项。 Use the checkout step with GitSCM, which has an extension to specify the Git tool to use. The git step has only a handful of the most common options as a convenience.
  • git merge --abort没有直接的等价物 - 在JGit中是不可用的。 这段代码可以作为一个起点: // clear the merge state repository.writeMergeCommitMsg( null ); repository.writeMergeHeads( null ); // reset the index and work directory to HEAD Git.wrap( repository ).reset().setMode( ResetType.HAR ...
  • RevWalk::isMergedInto()可用于确定提交是否已合并到另一个提交。 也就是说,如果第一个参数中给出的提交是第二个给定提交的祖先,则isMergedInto返回true。 try( RevWalk revWalk = new RevWalk( repository ) ) { RevCommit masterHead = revWalk.parseCommit( repository.resolve( "refs/heads/master" ); RevCommit otherHea ...
  • 您可以CommitTimeRevFilter#between(Date,Date)使用带有CommitTimeRevFilter#between(Date,Date) LogCommand#setRevFilter(RevFilter) CommitTimeRevFilter#between(Date,Date) ,例如: ObjectId masterId = git.getRepository().exactRef("refs/heads/master").getObjectId(); Date sin ...
  • 在Windows上运行代码,我可以重现您描述的内容。 这看起来像JGit中的一个错误。 我建议打开一个bugzilla或将你的发现发布到邮件列表中 。 Running the code on Windows, I can reproduce what you describe. This looks like a bug in JGit to me. I recommend to open a bugzilla or post your findings to the mailing list.
  • 我前段时间做了同样的搜索,但我得出结论,最好在Scala中使用JGit(即使它是一个Java库)。 它被具有大量用户的产品(eclipse,netbeans,gerrit,...)使用,甚至一些像Gitbucket这样的Scala产品也使用它。 它的API可以很容易地从Scala中调用,并且不会导致丑陋的代码,也不需要繁重的包装器。 就个人而言,我更喜欢使用广泛使用的Java lib而不是纯Scala lib,我不知道路线图,也不知道它是否仍在维护。 我想到了ScalaGit,但它看起来很年轻(只有67次提 ...
  • MergeCommand不是为了解决合并冲突。 相反,如果纳入的参考文献不能没有冲突地合并,将导致合并冲突。 PullCommand是一个复合命令 ,它首先从上游获取提交,然后尝试使用MergeCommand合并它们。 为了以编程方式解决合并冲突,您需要相应地更改本地工作目录中的文件,将它们添加到索引中,然后发出合并提交 。 有关冲突文件的信息可以在pullResult.getMergeResult()找到。 可以使用常规的CommitCommand创建合并提交 。 The MergeCommand is ...
  • JGit是Git的Java专用实现。 如果支持git mergetool ,则需要为可能执行JGit的每个平台包含各种本机mergetools。 我认为这就是为什么没有实施的原因。 此外, EGit (可能是主要的JGit使用者)使用Eclipse Compare Editor来解决冲突,因此不需要合并工具AFAIK。 以下是关于向EGit添加mergetool支持的讨论: https ://bugs.eclipse.org/bugs/show_bug.cgi ? id = 356832 如果您认为这应该在 ...
  • 如果您收到“拒绝连接”错误消息,那么(通常)意味着没有服务正在侦听客户端尝试连接的IP地址+端口。 确认此问题的常见技巧是使用其他一些实用程序尝试连接到问题IP +端口。 telnet实用程序通常用于此目的。 安装它(如有必要)并检查手动输入以查找用于指定端口号的命令行选项。 (这取决于你的操作系统......) 鉴于您说localhost正常工作,并且您使用的端口未被本地防火墙阻止,最可能的解释是您只配置了Git服务器软件以侦听localhost IP地址(通常为127.0.0.1 ) If you ge ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。