我一直在考虑如何将deque(即双端队列)实现为不可变数据结构.
似乎有不同的方法来做到这一点.AFAIK,不可变数据结构通常是分层的,因此在修改诸如插入或删除项之类的操作之后,可以重用它的主要部分.
Eric Lippert 在他的博客上有两篇 关于这个主题的文章,以及C#中的示例实现.
他的两个实现都让我觉得比实际需要更精细.难道deques只能被实现为二叉树,其中元素只能在树的"左"(前)和非"右"(后面)插入或删除?
o
/ \
… …
/ \
… …
/ \ / \
front --> L … … R <-- back
Run Code Online (Sandbox Code Playgroud)
此外,树将与旋转保持合理平衡:
在我看来,Eric Lippert是一个非常聪明的人,我非常尊重他,但他显然没有考虑这种方法.因此我想知道,这是有充分理由的吗?我建议的实施dequesnaïve的方法吗?
我正在学习Rails,并遇到了一个小问题.我正在使用任务列表编写死的简单应用程序,因此模型看起来像这样:
class List < ActiveRecord::Base
has_many :tasks
has_many :undone_tasks, :class_name => 'Task',
:foreign_key => 'task_id',
:conditions => 'done = false'
# ... some validations
end
Run Code Online (Sandbox Code Playgroud)
List模型表有列tasks_counter和undone_tasks_counter.
class Task < ActiveRecord::Base
belongs_to :list, :counter_cache => true
# .. some validations
end
Run Code Online (Sandbox Code Playgroud)
有了这样的代码存在attr_readonly :tasks_counter的List情况下,但我想有未完成的任务计数器为好.是否有任何方法让Rails自动缓存多个计数器.
到目前为止,我已经设法创建TasksObserver了增量或减量Task#undone_tasks_counter,但也许有一种更简单的方法.
我已经尝试了一段时间,但找不到合适的解决方案.
我想使用JSTL来检查我的Spring MVC 2.5中是否存在任何绑定错误(字段错误或全局错误).
我知道我可以使用这段代码:
<p>
<spring:hasBindErrors name="searchItems">
An Error has occured
</spring:hasBindErrors>
</p>
Run Code Online (Sandbox Code Playgroud)
但我想利用JSTL来检查是否有任何错误.
我使用JSTL尝试过这个:
<c:if test="${not empty errors}">
An Error has occured
</c:if>
Run Code Online (Sandbox Code Playgroud)
但似乎我无法正确捕捉它.
我需要使用JSTL,因为JSP的其他部分依赖于是否存在绑定错误.
可能重复:
何时使用final
final为对象
声明关键字有什么用?例如:
final Object obj = new myclass();
Run Code Online (Sandbox Code Playgroud) 表达式树和CodeDom之间有什么区别?我应该在哪种情况下使用哪个?
我想做两件事
创建一个私有实例变量,它是一个映射
在我的构造函数中创建一个空实例,它实现了一个地图并将其分配给前一个私有实例变量.
我拥有的私有实例是
private final Map<Character, SortedSet<String>> thesaurus =
new HashMap <Character, SortedSet<String>>();
Run Code Online (Sandbox Code Playgroud)
但是如何在构造函数中创建一个实例变量,该变量将在构造函数创建时引用私有变量同义词库.
例如
public class Book{
private final Map<Character, SortedSet<String>> thesaurus =
new HashMap <Character, SortedSet<String>>();
public Book(){
super();
/* What do i put here as an empty instance
* variable that implements a map and how
* do i assign it to thesaurus?
*/
}
Run Code Online (Sandbox Code Playgroud) 我知道在我的代码执行的同一目录中有一些文件.我需要找到它们并传递给另一种方法:
MyLib.dll
Target1.dll
Target2.dll
Foo(new[] { "..\\..\\Target1.dll", "..\\..\\Target2.dll" });
Run Code Online (Sandbox Code Playgroud)
所以我打电话System.IO.Directory.GetFiles(path, "*.dll").但现在我需要了解路径:
string path = new FileInfo((Assembly.GetExecutingAssembly().Location)).Directory.FullName)
Run Code Online (Sandbox Code Playgroud)
但还有更短的路吗?
如何限制以下代码以在下面的代码中生成8个混合字符和数字.
这是PHP代码.
md5(uniqid(rand(1,6)));
Run Code Online (Sandbox Code Playgroud) 我正在构建一个使用独立存储的Windows Phone 7应用程序.代码大多数时间都在工作,但我一直在随机获取IsolatedStorageExceptions:
{"An error occurred while accessing IsolatedStorage."}
There are no further details about the reason for the exception. Here is the stack trace:
at System.IO.IsolatedStorage.IsolatedStorageFile.DeleteFile(String file)
at MyApp.Core.Data.WindowsPhoneFileRepository.DeleteFile(String name)
at MyApp.Core.Domain.ThingService.SaveThing(Thing Thing)
at MyApp.Core.Domain.TrackedThingService.PersistThingLocally(TrackedThing Thing)
at MyApp.Ui.ViewModels.TrackViewModel.<.ctor>b__3(Thing Thing)
at GalaSoft.MvvmLight.Command.RelayCommand`1.Execute(Object parameter)
at GalaSoft.MvvmLight.Command.EventToCommand.Invoke(Object parameter)
at System.Windows.Interactivity.TriggerAction.CallInvoke(Object parameter)
at System.Windows.Interactivity.TriggerBase.InvokeActions(Object parameter)
at System.Windows.Interactivity.EventTriggerBase.OnEvent(EventArgs eventArgs)
at System.Windows.Interactivity.EventTriggerBase.OnEventImpl(Object sender, EventArgs eventArgs)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String …Run Code Online (Sandbox Code Playgroud) 我正在尝试从图像中删除所有白色或透明像素,留下实际图像(裁剪).我尝试了一些解决方案,但似乎都没有.有什么建议或者我打算过夜写图像裁剪代码?
c# ×3
java ×2
.net ×1
asp.net ×1
codedom ×1
crop ×1
deque ×1
gdi+ ×1
getfiles ×1
immutability ×1
php ×1
silverlight ×1
spring-mvc ×1