我必须为搜索引擎实现数据结构。因此,我的DS中存在不同类型的对象。我有一个通用的链接列表,我只想将那些不属于列表的元素添加到列表中。是否有一种方法可以更详尽地比较两种对象类型,因为.equals()每次都返回true?
/jsipp-master$ ruby curses.rb
Unable to load this gem. The libzmq library (or DLL) could not be found.
If this is a Windows platform, make sure libzmq.dll is on the PATH.
If the DLL was built with mingw, make sure the other two dependent DLLs,
libgcc_s_sjlj-1.dll and libstdc++6.dll, are also on the PATH.
For non-Windows platforms, make sure libzmq is located in this search path:
["/Library/Ruby/Gems/2.3.0/gems/ffi-rzmq-core-1.0.6/lib/ffi-rzmq-core/../../ext/libzmq.dylib", "/usr/local/bin/libzmq.dylib", "/usr/bin/libzmq.dylib", "/bin/libzmq.dylib", "/usr/sbin/libzmq.dylib", "/sbin/libzmq.dylib", "/opt/X11/bin/libzmq.dylib", "/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/libzmq.dylib", "/usr/local/lib/libzmq.dylib", "/opt/local/lib/libzmq.dylib", "/usr/local/lib/libzmq.dylib", "/usr/lib64/libzmq.dylib"]
/Library/Ruby/Gems/2.3.0/gems/ffi-rzmq-core-1.0.6/lib/ffi-rzmq-core/libzmq.rb:61:in `rescue in <module:LibZMQ>': The libzmq library (or DLL) could not be loaded (LoadError)
from /Library/Ruby/Gems/2.3.0/gems/ffi-rzmq-core-1.0.6/lib/ffi-rzmq-core/libzmq.rb:10:in `<module:LibZMQ>'
from /Library/Ruby/Gems/2.3.0/gems/ffi-rzmq-core-1.0.6/lib/ffi-rzmq-core/libzmq.rb:7:in `<top (required)>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Library/Ruby/Gems/2.3.0/gems/ffi-rzmq-core-1.0.6/lib/ffi-rzmq-core.rb:3:in `<top (required)>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Library/Ruby/Gems/2.3.0/gems/ffi-rzmq-2.0.6/lib/ffi-rzmq.rb:66:in `<top (required)>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `rescue in require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in `require'
from curses.rb:4:in `<main>'
这是LinkedList的isMember方法。这仅适用于字符串类型。我可以对此进行哪些更改以使其适用于所有对象类型?
如果我为正在使用的不同对象定义isEqual方法,该如何在这里使用这些方法?
答案 0 :(得分:1)
您将必须实现您的.equals()版本。要比较列表,这里有一些问题对您有帮助
returning difference between two lists in java
Simple way to find if two different lists contain exactly the same elements?
答案 1 :(得分:0)
每当为不同的对象定义isEqual方法时,即在isMequal调用时使用的方法,例如isMember。