it strikes me that bitset operations are very similar to operations
on large integers. you could actually use big.Int as an underlying
implementation. the only problem being that big.Int makes it quite
inefficient to twiddle numbered bits (each operation involves at least
one allocation).
if SetBit and Bit methods were added to big.Int, perhaps there would be no
need for a separate bitset package.
package bits
import "big"
type Bits big.Int
var zero = new(big.Int)
func mask(n int) *big.Int {
m := big.NewInt(1)
return m.Lsh(m, uint(n))
}
func (b *Bits) Get(i int) bool {
n := (*big.Int)(b)
m := mask(i)
return zero.Cmp(m.And(n, m)) == 0
}
func (b *Bits) Set(i int) {
n := (*big.Int)(b)
n.Or(n, mask(i))
}
func (b0 *Bits) Union(b1 *Bits) {
n0 := (*big.Int)(b0)
n0.Or(n0, (*big.Int)(b1))
yes, but does it matter if the bitset is a little bit larger than requested?
It should panic. There is no good reason for a package to avoid panicking when the programmer uses the package wrong. However, you don't want packages panicking in unpredictable ways, e.g. when a file can't be opened etc.
Ryanne
Also, I've added a Size() method
Michael T. Jones
Chief Technology Advocate, Google Inc.
1600 Amphitheatre Parkway, Mountain View, California 94043
Email: m...@google.com Mobile: 650-335-5765 Fax: 650-649-1938
Organizing the world's information to make it universally accessible and useful
it also allows "negative" sets, which are a useful generalisation.
http://code.google.com/p/inferno-os/source/browse/appl/lib/sets.b
Frequently in bit strings there is a desire for the four functions:find {first|last}{one|zero}
if you document that getting or setting a bit beyond the
limit gives rise to undefined behaviour, then it doesn't matter.
personally, i think if you're going to use a slice, you might
as well make the set arbitrary size and extend the slice
as necessary.
Agree.
Ryanne
Zhai,I'd be glad to write the unit tests, if you want to clone the git repository or do a fork and edit in place for the new code, as described at https://github.com/blog/844-forking-with-the-edit-button.
func (b *BitSet) Sub(start, end uint) *BitSet {
ipos := start & (32 - 1)ifirst := start >> 32icount := end - startilen := icount >> 32
I'm trying to make a simple SOAP request using SOAP. I tried using
Client.Do and Client.Post.
// with Do
func testSoap() {
httpClient := new (http.Client)
soapRequestContent := "<?xml version=\"1.0\" encoding=\"UTF-8\"
standalone=\"no\"?><SOAP-ENV:En ... elope>"
httpRequest, err := http.NewRequest("POST", "http://aSoapServer/",
strings.NewReader(soapRequestContent))
httpRequest.Header.Set("SOAPAction", "anAction")
httpRequest.Header.Set("Content-Type", "application/soap+xml;
charset=utf-8")
httpRequest.Header.Set("Content-Length", fmt.Sprintf("%d",
len(soapRequestContent)))
resp, err := httpClient.Do(httpRequest)
if err!=nil {
fmt.Println("Erreur : " + err.String())
}
r := bufio.NewReader(resp.Body)
line, err := r.ReadString('\n')
for err == nil {
fmt.Print(line)
line, err = r.ReadString('\n')
}
if err != os.EOF {
fmt.Println("Erreur lecture :")
fmt.Println(err)
}
resp.Body.Close()
fmt.Println();
}
With this method, my string (soapRequestContent) doesn't seem to be
posted as body of my request (there must be a bug in my code but I don't
see it).
// with Post
func testSoap() {
httpClient := new (http.Client)
soapRequestContent := "<?xml version=\"1.0\" encoding=\"UTF-8\"
standalone=\"no\"?><SOAP-ENV:En ... elope>"
resp, err := httpClient.Post("http://aSoapServer/",
"application/soap+xml; charset=utf-8",
strings.NewReader(soapRequestContent))
if err!=nil {
fmt.Println("Erreur : " + err.String())
}
r := bufio.NewReader(resp.Body)
line, err := r.ReadString('\n')
for err == nil {
fmt.Print(line)
line, err = r.ReadString('\n')
}
if err != os.EOF {
fmt.Println("Erreur lecture :")
fmt.Println(err)
}
resp.Body.Close()
fmt.Println();
}
With this method my body is correctly sent but I cannot specify the
SOAPAction header.
As I'm totally new to SOAP I may do something fundamentally wrong... Is
there somewhere an example of a simple SOAP interrogation in go ?
Complement, surely?
Chris
--
Chris "why, yes, it is a trigger for me, how did you know?" Dollin
Maybe. "That was the finest bit flip ever. I compliment you on your complement!"
ron
"Invert" has the appropriate meaning and is more compact ...
Chris
--
Chris "invirt, compect -- Clouseau?" Dollin
inspired by your package, i've created a CL that adds Bit and SetBit
methods to big.Int
(see http://codereview.appspot.com/4538053/)
this would mean that big.Int would provide most of the
functionality of the bitset package at similar runtime cost
(admittedly the methods would not be quite so obviously
named, Union->Or, Difference->AndNot, Intersection->And,
Symmetric Difference->Xor, etc).
big.Int provides destructive and non-destructive versions
of all its operations (through the use of 3-operand functions).
there are still some operations that will be slow using bit.Int,
bit counting being one, although it has the advantage of already
working with quite a few other parts of the standard Go library
(e.g. random number generation).
Hi.Not sure if this is the right place to ask, but I need a way to reverse the BitSet.Currently the first stays on the right and grows toward the left, but I'm creating a package to handle ISO8583 messages and I need the fields to be identified from left to right.
Is this possible to do with bitset library?
Thank you.
Now it's perfect.Give me your full name, the file will have your name on it (planning to "open source it" when its ready).